C
collection60
Hi people,
I am writing a library that will implement a binary file format.
Well... I'm thinking, as a design, it would be nice to have my library
able to promise to not use more than a certain amount of RAM. I could
have a "SetCacheSize(long NewSize);" function. So as part of that
promise, when required memory exceeds that limit, the extra data is
saved to disk and flushed from RAM.
Now to keep that promise, it would be nice to have some control over
the memory management. For example, with malloc, you can't really be
sure of how much RAM is allocated. I'd like to just allocate a block,
say 16MB at first, and then suballocate out of there. I'd also like to
know if I can't allocate from that 16MB (or whatever size it is), so I
can start freeing cached data.
I heard that C++ allocators might be a solution. I've never used
allocators before, but they look promising. For me to use single
allocators, I'd like these qualities.
1) Portable across the main desktop platforms (linux, win32, Mac)
2) Quite fast. Single-threaded is fine if it helps increase speed.
3) Pooled allocation. I pre-define a maximum size that it can allocate
out of, and it allocates out of there. It could pre-allocate the entire
amount, or just allocate in blocks that will never become more than
this limit.
4) Lets me know if we have enough space to allocate another object, or
it's design is simple enough that I can figure out for my self if we
have enough space within the pool. (If not, I'll just flush many
objects to the disk and free up some RAM )
5) Doesn't suck
Any ideas anyone? Like I said, I don't know anything about allocators.
would gcc's "__pool_alloc" do this for me?
I am writing a library that will implement a binary file format.
Well... I'm thinking, as a design, it would be nice to have my library
able to promise to not use more than a certain amount of RAM. I could
have a "SetCacheSize(long NewSize);" function. So as part of that
promise, when required memory exceeds that limit, the extra data is
saved to disk and flushed from RAM.
Now to keep that promise, it would be nice to have some control over
the memory management. For example, with malloc, you can't really be
sure of how much RAM is allocated. I'd like to just allocate a block,
say 16MB at first, and then suballocate out of there. I'd also like to
know if I can't allocate from that 16MB (or whatever size it is), so I
can start freeing cached data.
I heard that C++ allocators might be a solution. I've never used
allocators before, but they look promising. For me to use single
allocators, I'd like these qualities.
1) Portable across the main desktop platforms (linux, win32, Mac)
2) Quite fast. Single-threaded is fine if it helps increase speed.
3) Pooled allocation. I pre-define a maximum size that it can allocate
out of, and it allocates out of there. It could pre-allocate the entire
amount, or just allocate in blocks that will never become more than
this limit.
4) Lets me know if we have enough space to allocate another object, or
it's design is simple enough that I can figure out for my self if we
have enough space within the pool. (If not, I'll just flush many
objects to the disk and free up some RAM )
5) Doesn't suck
Any ideas anyone? Like I said, I don't know anything about allocators.
would gcc's "__pool_alloc" do this for me?