|
Hi all,
I created a map file like this :
HANDLE hMap=CreateFileMapping(hFile, NULL, _dwProtect, 0, _dwSize, _strMapName);
but now I need to increase its size and create a new view on it!! does someone know how to to that the right way??
Thank you so much
|
|
|
|
|
hatemtalbi wrote: but now I need to...create a new view on it!!
To start over, can't you just call UnmapViewOfFile() followed by CloseHandle() ?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Yes, I did all that. But when I call mapViewOfFile() the secon time the whole size of the maapped file !!!
|
|
|
|
|
hatemtalbi wrote: But when I call mapViewOfFile() the secon time the whole size of the maapped file !!!
Your sentence is incomplete. What happens when you call MapViewOfFile() the second time?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
for example when I resize the file from 4KB to 8KB, I expect that MapViewOfFile() return a buffer size of 8KB but I get only 4KB !!!
|
|
|
|
|
This is to be expected - that is how file-mapping objects work.
You should use the ZwResizeSection native-API if you want to resize the file-mapping object. Lots of info on google about this.
James
http://www.catch22.net
|
|
|
|
|
Sorry, I typed ZwResizeSection in google but I didn't get any results !!
please could you check the word orthography
thank you
|
|
|
|
|
|
Hi,
I would like to change the standard CTabCtrl to get a little button on the far right side.
The number of tabs should be dynamic, so the control must reserve some space for the button (it shall not draw over the button when there is a high number of tabs). Do I need to write an ownerdraw control or maybe I can reuse CTabCtrl? Thanks for help.
/M
|
|
|
|
|
|
Does this mean I have to write an ownerdraw control to get this functionality?
|
|
|
|
|
Hey,
does someone know how to check if a pointer is valid (was allocated by the application and can be used without problem) or no?
|
|
|
|
|
Have you looked into IsBadCodePtr() , IsBadReadPtr() , IsBadWritePtr() , or IsBadStringPtr() ?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
You are asking for trouble if you rely on these APIs to tell if memory is safe to use. For example with heaps when you free a block it doesn't mean the memory is deallocated straight away; it can be marked as free and recycled. This is how heaps work. In short if IsBadReadPtr returns TRUE you know for sure that the memory isn't safe to read; but if it returns FALSE it does ***NOT*** mean that the memory is safe to use - it could be on the heap's free list for example. These API are only meant for debugging purposes and not for memory management in the manner your post alludes to.
Steve
|
|
|
|
|
Stephen Hewitt wrote: These API are only meant for debugging purposes and not for memory management in the manner your post alludes to.
Hence my question.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
In Windows you can try IsBadReadPtr , IsBadWritePtr and IsBadStringPtr .
In MFC you can try AfxIsValidAddress and AfxIsValidString .
In case of run-time library, you can try _CrtIsValidPointer , _CrtIsValidHeapPointer and _CrtIsMemoryBlock .
|
|
|
|
|
AfxIsValidAddress worked fine for me.
Thanks a lots
|
|
|
|
|
You are asking for trouble if you rely on these APIs to tell if memory is safe to use. For example with heaps when you free a block it doesn't mean the memory is deallocated straight away; it can be marked as free and recycled. This is how heaps work. For example: if IsBadReadPtr returns TRUE you know for sure that the memory isn't safe to read; but if it returns FALSE it does ***NOT*** mean that the memory is safe to read - it could be on the heap's free list for example.
Most people don't believe when I tell them this. The following code shows this effect in action:
int *pInt = new int;
delete pInt;
ASSERT( AfxIsValidAddress(pInt, sizeof(int)) );
If this practice was safe the ASSERT should fire: it doesn't. The memory is being cached in the heap but it is definitely ***NOT*** safe to use it. DO NOT USE THIS TECHNIQUE!
Steve
|
|
|
|
|
Stephen Hewitt wrote: If this practice was safe the ASSERT should fire: it doesn't.
Actually, it should only fire if the address pointed to by pInt was not contained entirely within the program’s memory space.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: Actually, it should only fire if the address pointed to by pInt was not contained entirely within the program’s memory space.
Yes, that's what the API does. This doesn't contradict my statement. The OP wanted to know how to tell if memory "was allocated by the application and can be used without problem". AfxIsValidAddress was put forward as a solution and the OP accepted it claiming that it worked. I pointed out that if this API could be used to perform this function then the ASSERT in the code below should fire as AfxIsValidAddress should return FALSE given that it is surely not safe to use a pointer after it has been deleted:
int *pInt = new int;
delete pInt;
ASSERT( AfxIsValidAddress(pInt, sizeof(int)) );
This is not the case. If you try this code AfxIsValidAddress returns TRUE and thus the ASSERT will not fire. Why? Because the address pointed to by pInt was entirely contained in the process’s address space. It's cached by the heap (the small block heap in this case) for recycling. So the problem is that just because an address is physically mapped into the process's address space doesn't mean it's safe to use.
In general these APIs can only be used to tell if memory can't be safely used but not to tell if it is safe to use.
Steve
|
|
|
|
|
Best programs always handle the pointers validity by checking NULL or not. for this you should cautious about allocation and de-allocation
SaRath.
"Do Next Thing..."
My Blog | Understanding State Pattern in C++
|
|
|
|
|
hatemtalbi wrote: does someone know how to check if a pointer is valid (was allocated by the application and can be used without problem) or no?
When you ask that question something is wrong in your code. You should never have to check if a pointer is 'valid'.
|
|
|
|
|
I agree 100%. You get a five for making so much sense.
Steve
|
|
|
|
|
Hi,
i need to know a way to read the motherboard sensors (temp, speed...) using C++. Just like MBM.
Grateful!
Honae
Edit/Delete Message
|
|
|
|
|
Have you checked out the various WMI classes?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|