Article # 152, added by Geoworks, historical record
| first |
previous |
index |
next |
last |
Finding the total size of an LMem block
Question: ========== When I type "lhwalk" for an object block of an application, Swat tells me the size is 4524 bytes. When I add up the sizes of the objects & chunks within the block, however, I get 4269 bytes. Swat also tells me the number of handles for this block is 40, so I figure another 80 bytes for the chunk handle table. Add in another 16 bytes for the LMemBlockHeader and the total is 4365 bytes. Additionally, Swat says there is no free space, and it shows no free chunks in the lhwalk. So why the discrepancy (4524 vs 4365) ? What am I doing wrong ? Answer: ======== What you're forgetting is the overhead in chunk sizes. Remember that chunks are padded to be dword-aligned. Also, the size of the chunk is stored in the word preceding the chunk data. So, each chunk has different overhead: 2 to 5 bytes for each chunk. Here's how to calculate the exact LMem block size: LMBH_blockSize = chunk sizes + free space + LMem header + Chunk Handle table size + chunk size overhead = sum( chunk sizes ) + LMBH_totalFree + LMBH_offset + (LMBH_nHandles x 2) + sum( overhead )