Is there no way you can allocate your memory using MemHandleNew, and then
simply lock it down (MemHandleLock) as you need to access it?  After all,
that's the way the OS was designed to be used...

Another alternative (which you're playing with breaking rules) is to
allocate the memory in the storage heap, and if you need fast random write
access to it, simply tweak the Semaphores to allow it.  This method would
also bypass the requirement to use MemPtrSetOwner, and also (depending on
creator codes chosen) give you the added bonus of automagicly deleting all
your allocated memory when your app is deleted.

Alan
Profitlink Consulting

"Eric House" <[EMAIL PROTECTED]> wrote in message news:112577@palm-dev-forum...
>
> I'm working on an app that maintains a significant memory presence in
> the heap for as long as the device is running.  That is, it will set
> the OwnerId of the blocks it requests to 0 so that they don't get
> cleaned up each time PilotMain exits.  In effect, it'll take
> responsibility for its own memory management.
>
> Right now it just uses MemPtrNew (with MemPtrSetOwner) and MemPtrFree.
> But we're finding that over the uptime of a device we get significant
> fragmentation in the heap.  We run and allocate.  Then another app
> runs and allocates in the space we've left free.  Then it quits and we
> run and allocate and free some more.
>
> I *think* (but would be happy to be told I'm wrong) that the best
> solution to this it to write our own allocator.  The first time we're
> launched we'd ask PalmOS for a number of large chunks low in the heap,
> make them permanent, and we'd do all subsequent allocations out of
> those chunks.  Pretty standard CS stuff.
>
> Assuming that's the right way to go, can anyone point me at
> discussions or even code for allocators suitable for a non-ARM Palm
> device.  I'm looking at Doug Lea's popular allocator
> (http://g.oswego.edu/dl/html/malloc.html) but am afraid it'll be too
> heavyweight for our purposes.  Other suggestions?
>
> (BTW, I don't want to get into a discussion about what a bad citizen
> I'm being by hogging all this memory.  The app in question will be
> installed on devices that are purchased specifically to run the app.
> Strictly speaking it's not a requirement that we allow any third-party
> apps to run, but of course we want to be the best citizens we can.  We
> want to make sure there's room for third-party apps to work well.)
>
> (Also, I know that the right way to do this is to break our allocations
> out into frequently-written blocks, which would go in the heap, and
> infrequently-written blocks, which could go in storage memory.
> Unfortunatly that isn't an option, as most of the code was originally
> written for other platforms that didn't have that distinction and must
> remain cross-platform.)
>
> Thanks,
>
> --Eric House
> --
>
****************************************************************************
**
> * From the desktop of: Eric House, [EMAIL PROTECTED]
*
> *    Crosswords 4.0 for PalmOS is out!:
<http://www.peak.org/~fixin/xwords>  *
>
****************************************************************************
**
>
>



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to