I use the following bunch of code in ClieSkinner/SkinDIA/SkinTW for creating a
big resource. The code is quite reliable--I haven't had a bug report traceable
to this code area since last summer. You can no doubt modify it for a big
record. Note that such DBs can cause trouble for backup applications. Feel
free to use under the BSD 2-clause license at the end (closed source use is OK).
#define memMaxChunkAllocSize 65505ul
#define memNewChunkFlagAllowLarge 0x1000
#define dmOrphanOwnerID 3
MemHandle BigNewResource( DmOpenRef ref, UInt32 type, UInt16 id, UInt32 size )
{
UInt16 i;
UInt16 n;
UInt16 card;
if ( size <= memMaxChunkAllocSize )
return DmNewResource( ref, type, id, size );
for ( card = 0 ; card < 1 ; card++ ) {
n = MemNumHeaps( card );
for ( i = 0 ; i < n ; i++ ) {
UInt16 heapID;
UInt16 flags;
heapID = MemHeapID( card, i );
flags = MemHeapFlags( heapID );
if ( ! ( flags & memHeapFlagReadOnly ) && ! MemHeapDynamic( heapID
) ) {
MemHandle h;
h = MemChunkNew( heapID, size, dmOrphanOwnerID |
memNewChunkFlagAllowLarge );
if ( h != NULL ) {
if ( errNone == DmAttachResource( ref, h, type, id ) ) {
UInt16 index;
index = DmFindResource( ref, type, id, NULL );
if ( index != 0xFFFFu ) {
return DmGetResourceIndex( ref, index );
}
else {
return NULL;
}
}
MemChunkFree( h );
}
}
}
}
return NULL;
}
/*
Copyright (c) 2004-05, Alexander R. Pruss
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/