Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Dynamically growable/shrinkable block of RAM?



Hi list,

In essence, my question is: "Whats the most efficient way to dynamically shrink and grow a block of allocated RAM, using the least copy actions possible, while also allowing the area of RAM in shrunk blocks to be reused by other code".

For one of my libraries, I'm making a class which has a dynamically growable and shrinkable buffer. Its pretty much like the Java class "StringBuffer".

So, right now, I'm using malloc/realloc, which in turn on OSX, is a wrapper to NewPtr and BlockMoveData. This wrapping is done by CodeWarrior's libraries (which of course the source to is included!)

I'm thinking that that really isn't good enough. For example, isn't it possible to shrink the buffer "in place"? What about growing "in place"? Yes CodeWarrior CAN do it actually, but only up to a certain block size!

But... the kicker is, that its more important to grow/shrink a block in place, on *large* blocks, not small ones! Just for CPU time's sake!

I've heard that SetPtrSize on OSX, will not shrink a block of RAM. It marks it as shrunk, but all the bytes are not freed up for reuse.

So, I'm thinking I could forget malloc/realloc, and go directly with NewHandle, SetHandleSize.

Would this do what I want??

Hence "Whats the most efficient way to dynamically shrink and grow a block of allocated RAM, using the least copy actions possible, while also allowing the area of RAM in shrunk blocks to be reused by other code".
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.