Memory problem in CSharedFile.
-
Hi, I found a peculiar problem when using CSharedFile. Requirement: I have data present in (BYTE*) which needs to be converted to HGLOBAL. The data is segmented, that is the entire data is present in 2-3 BYTE*. What was done: a) Created a CSharedFile and attached it to a CArchive object. Then the entire BYTE* data was archived using a while loop for each BYTE*. b) Called CSharedFile::Detach to obtain the HGLOBAL data. Problem: The actual size of the data is 1184 bytes. But when checking the actual size of the memory allocated using GlobalSize() function the return value was 8192!!! Please let me know what could be the reason for this? You can reach me at s_adityapalanki@yahoo.com Thanks and regards, Aditya Palanki
-
Hi, I found a peculiar problem when using CSharedFile. Requirement: I have data present in (BYTE*) which needs to be converted to HGLOBAL. The data is segmented, that is the entire data is present in 2-3 BYTE*. What was done: a) Created a CSharedFile and attached it to a CArchive object. Then the entire BYTE* data was archived using a while loop for each BYTE*. b) Called CSharedFile::Detach to obtain the HGLOBAL data. Problem: The actual size of the data is 1184 bytes. But when checking the actual size of the memory allocated using GlobalSize() function the return value was 8192!!! Please let me know what could be the reason for this? You can reach me at s_adityapalanki@yahoo.com Thanks and regards, Aditya Palanki
This is the documented behaviour for
GlobalSize
. -
This is the documented behaviour for
GlobalSize
.Dear Johan, Does this mean that the extra memory that is being allocated is normal? Can you suggest any other way of creating an HGLOBAL? Regards, Aditya Palanki
-
Dear Johan, Does this mean that the extra memory that is being allocated is normal? Can you suggest any other way of creating an HGLOBAL? Regards, Aditya Palanki
Aditya_Palanki wrote: Does this mean that the extra memory that is being allocated is normal? Yes, it allocates in blocks. If your allocation size is not an exact multiple of the block, you'll get extra padding. Aditya_Palanki wrote: Can you suggest any other way of creating an HGLOBAL?
GlobalAlloc
is the way of doing it. If the receiver needs to know the size actually allocated, just add this value to the beginning of the block, for example.