Showing results 1 to 2 of 2

Thread: Memory Pools

  1. #1
    Formerly Known as Jakor Senior Member
    Developer

    Evangelist
    laocoon's Avatar
    Join Date
    Jan 2005
    Posts
    1,280

    Default Memory Pools

    So. I have long been known to just release tools or libraries. I kinda like the idea of writing something in assembly that can be useful to developers by just plugging in fast code where they don't quite have the control. Not saying that I write the fastest code, or its the most optimized, but just I like writting back ends and not dealing with too much in the way of graphics.

    I've had a problem with allocating memory for a long time now. I didn't like how c++ gets a malloc(SIZE) and we have to feed extra parameters to virtualalloc. It seems like messy code. If I decide to use a virtualalloc every time I want to make a new instance of a structure, as long as my structure is 1000h bytes or less, my structures take up 1000h bytes each in memory. So after looking around I decided to write my own memory pool. Basically, I'll allocate more memory than I need one time, and I'll pull from that memory after that. (Arrays are great, but from a library perspective, you don't know if someone will use one "ListViewController" or 1000 and a 100h byte structure holding all the information you don't want 1000 arrays of)

    I saw a few examples in c or whatever. They all seemed to have some cool features here and there, but I decided to write my own. I have some other features I would like to add (dynamically expanding / contracting pools) or (my defrag function to work *I haven't tested it*), however I got around the expanding and contracting by being able to create multiple pools. If memAlloc returns 0, use memInit to make a new pool and start again with that one.

    I was bored at work in between customers today. Here's what I got so far:

    memInit
    memRelease
    memAlloc
    memFree

    all work
    internally merge works as well

    I'm sure there are a few bugs in the defrag routine as well. I merge on free because it doesn't take *much* processing. defragging was more of a puzzle to solve because it writes so much that it would slow down memAlloc memFree..
    Attached Files Attached Files

  2. #2

    Advocate
    Shimano's Avatar
    Join Date
    Jan 2007
    Location
    Boise, ID
    Posts
    309

    Default

    This is pretty neat, do you think you could put it up on github for pull requests? I have a feeling this is out of date :p

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. PSP memory?
    By Loser777 in forum Hardware and Software
    Replies: 30
    Last Post: 12-27-2006, 05:45 PM
  2. [Help] need memory loader
    By arg_life in forum Starcraft/Brood War
    Replies: 1
    Last Post: 12-26-2006, 10:04 AM
  3. Why are all my processes using so much memory?
    By Loser777 in forum Hardware and Software
    Replies: 16
    Last Post: 09-27-2006, 12:02 PM

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •