Article # 120, added by Geoworks, historical record
| first | previous | index | next | last |

How to retrieve a Chunk or ChunkArray from a VMFile




It is easy to store a LMem block in a VMFile.  To open a VMFile and
retrieve a chunk from its LMem block is a little more challanging.  
The reason is that you need the ChunkHandle to dereference the chunk,
but you don't necessarily know what ChunkHandles to use for this newly
loaded block.  

Well, actually you do know the ChunkHandle.  The ChunkHandles are stored
in the ChunkHandle table which is referenced by LMBH_offset of the
LMemBlockHeader.  This is most useful when there is only one large chunk
in the block (such as a ChunkArray).  You access the ChunkHandle, like
this:

optr MyGetChunkOptrRoutine(VMFileHandle file, VMBlockHandle block)
{
    LMemBlockHeader *blockHeader;
    MemHandle blockHandle;
    ChunkHandle chunkHandle;

    blockHeader = VMLock(file, block, &blockHandle);

    chunkHandle = blockHeader->LMBH_offset;

    return (ConstructOptr(blockHandle, chunkHandle));
}


If you are storing a LMemBlock with many chunks in it, your best bet is to
save the ChunkHandles to the VMFile's mapblock for easy retrieval.