Hello All,
I’m developing a DLL which uses DIM...AT lpMem1 to create and manipulate several arrays.
I use:
then:
and also:
whenever I need to change the size of the arrays. The application is not finished so I cannot yet test the code, however I’m starting to think the above logic may fail.
For DIM..AT lpMem2 to work, lpMem2 must point to non-fragmented memory. However, using the above code, increasing the size of memory at lpMem2 must result in either its memory being fragmented or memory at lpMem3 being corrupted – doesn’t it?
I can only see one option and that is to redo the code to only one use of HeapAlloc() and allocate enough memory for all 3 arrays, as in:
and then calculate the offsets for the other pointers, as in:
Of course, I’ll have to use MoveMemory() after every HeapReAlloc() to move ensure the pointers are correct.
Can anyone see any problems, or a more effective solution?
Pat
I’m developing a DLL which uses DIM...AT lpMem1 to create and manipulate several arrays.
I use:
Code:
ghHeap = HeapCreate( %HEAP_GENERATE_EXCEPTIONS _ OR %HEAP_NO_SERIALIZE, _ 0, 0 )
then:
Code:
lpMem1 = HeapAlloc( ghHeap, _ %HEAP_ZERO_MEMORY OR _ %HEAP_NO_SERIALIZE OR _ %HEAP_GENERATE_EXCEPTIONS, _ lBytes1 ) lpMem2 = HeapAlloc( ghHeap, _ %HEAP_ZERO_MEMORY OR _ %HEAP_NO_SERIALIZE OR _ %HEAP_GENERATE_EXCEPTIONS, _ lBytes2 ) lpMem3 = HeapAlloc( ghHeap, _ %HEAP_ZERO_MEMORY OR _ %HEAP_NO_SERIALIZE OR _ %HEAP_GENERATE_EXCEPTIONS, _ lBytes3 )
and also:
Code:
lpMem2 = HeapReAlloc( ghHeap, _ %HEAP_ZERO_MEMORY OR _ %HEAP_NO_SERIALIZE OR _ %HEAP_GENERATE_EXCEPTIONS, _ hExitingHandle, _ lNewBytes2 )
whenever I need to change the size of the arrays. The application is not finished so I cannot yet test the code, however I’m starting to think the above logic may fail.
For DIM..AT lpMem2 to work, lpMem2 must point to non-fragmented memory. However, using the above code, increasing the size of memory at lpMem2 must result in either its memory being fragmented or memory at lpMem3 being corrupted – doesn’t it?
I can only see one option and that is to redo the code to only one use of HeapAlloc() and allocate enough memory for all 3 arrays, as in:
Code:
lpMem1 = HeapAlloc( ghHeap, _ %HEAP_ZERO_MEMORY OR _ %HEAP_NO_SERIALIZE OR _ %HEAP_GENERATE_EXCEPTIONS, _ lBytes1 + lBytes2 + lBytes3 )
and then calculate the offsets for the other pointers, as in:
Code:
lpMem2 = lpMem1 + lBytes1 lpMem3 = lpMem2 + lBytes2
Can anyone see any problems, or a more effective solution?
Pat
Comment