Memory buffer size
-
Hi, Is there any way to get the size of an allocated memory buffer knowing only the its address? Thank you all :)
-
Hi, Is there any way to get the size of an allocated memory buffer knowing only the its address? Thank you all :)
-
No :( it doesn't worked for me !!! The _msize function returns the size, in bytes, of the memory block allocated by a call to calloc, malloc, or realloc. Thank you anyway
-
Hi, Is there any way to get the size of an allocated memory buffer knowing only the its address? Thank you all :)
The short answer, is no. The long answer is that if you know something about the memory, you may be able to. For example, if it is a
BSTR
you can look 4 bytes before its "handled" address or useSysStringLen(...)
. If you know that the memory came from a particular heap (or heap manager), you may be able to crack the heap structures used to maintain memory allocations. You also need to know where the memory came from in order to use functions like_msize(...)
,_msize_dbg(...)
,GlobalSize(...)
, etc. Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!) -
The short answer, is no. The long answer is that if you know something about the memory, you may be able to. For example, if it is a
BSTR
you can look 4 bytes before its "handled" address or useSysStringLen(...)
. If you know that the memory came from a particular heap (or heap manager), you may be able to crack the heap structures used to maintain memory allocations. You also need to know where the memory came from in order to use functions like_msize(...)
,_msize_dbg(...)
,GlobalSize(...)
, etc. Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!)Here it is: LPVOID data = MapViewOfFile(m_hMap, _dwDesiredAccess, 0, _dwOffset, _dwNbBytes); I need to know the size of the data buffer. I call this code after resizing a map file with 8ko but I can acess only the first 4ko :( could someone help me?!!
-
Here it is: LPVOID data = MapViewOfFile(m_hMap, _dwDesiredAccess, 0, _dwOffset, _dwNbBytes); I need to know the size of the data buffer. I call this code after resizing a map file with 8ko but I can acess only the first 4ko :( could someone help me?!!
hatemtalbi wrote:
I need to know the size of the data buffer.
Isn't that what
_dwNbBytes
represents?hatemtalbi wrote:
I call this code after resizing a map file with 8ko but I can acess only the first 4ko
What in the world is "ko?"
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
-
No :( it doesn't worked for me !!! The _msize function returns the size, in bytes, of the memory block allocated by a call to calloc, malloc, or realloc. Thank you anyway
In case of objects allocated with
new
operator, the number of items seems to be stored in a word before the pointer:MyClass * a = new MyClass[10]; __int32 size = *(((__int32*)a) - 1); // contains 10
This works only when the class contains destructor. The size does not seem to be stored in such manner for destructor-less objects and for fundamental types. But for this cases,
_msize
appears to return the size in bytes. -
hatemtalbi wrote:
I need to know the size of the data buffer.
Isn't that what
_dwNbBytes
represents?hatemtalbi wrote:
I call this code after resizing a map file with 8ko but I can acess only the first 4ko
What in the world is "ko?"
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
no, _dwNbBytes == 0 ko mean kb == 1024 bytes thx
-
no, _dwNbBytes == 0 ko mean kb == 1024 bytes thx
hatemtalbi wrote:
no, _dwNbBytes == 0
Then you simply need to look at the size of the file, since the entire file was mapped.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
-
hatemtalbi wrote:
no, _dwNbBytes == 0
Then you simply need to look at the size of the file, since the entire file was mapped.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
that s the problem!!! it seems that the size of the file is larger than the memory buffer returned. I don't understand why :(