|
When you allocate 128 bytes through "new char[128]", you may not commit any new page of memory!!!
My point is that memory allocation is done by the heap manager used by your module. For example, if CRT is the heap manager (msvcrt.dll) you're linking with, all "malloc / new" kind of instructions will be handled by that library, which may reuse previously released memory, or return an address of already commited memory. The heap manager keeps track of your allocations, and commits pages of memory only when needed. For example, on first allocation, a number of pages are commited to support the request. On those pages there's still room for more allocations. Thus, next allocation, if small enough, will not commit more pages, but use the existing commited pages.
There're plenty of online resources explaining how a "heap manager" implementation works:
http://blogs.technet.com/askperf/archive/2007/06/26/what-a-heap-of-part-one.aspx[^]
http://en.wikipedia.org/wiki/Chunking_(computing)[^]
http://www.blackhat.com/presentations/bh-usa-06/BH-US-06-Marinescu.pdf[^]
http://www.freshpatents.com/Methods-systems-and-computer-program-products-for-managing-a-memory-by-storing-external-objects-in-a-dynamic-heap-dt20051215ptan20050278496.php[^]
Best regards,
|
|
|
|
|
Does WM_COPYDATA use some kind of shared memory concept when it uses the structure COPYDATASTRUCT?
|
|
|
|
|
When sending WM_COPYDATA message to another application, lParam must point to a COPYDATASTRUCT, and the passed data must not contain any addresses (pointers or references) that would not be available in the other process. Until the thread sending the message returns from the call, the data structure should be either locked or not modified by other threads of the calling process. The data received by the other process cannot modify / return any of the structure's content. The reason behind all these is that the OS is copying the given structure as a block, from the calling process to the receiving process. It is like calling WriteProcessMemory, on some temp variable (thread stack address) in the target process. The communication is one way!
Regards,
|
|
|
|
|
While using the structure could we say that the OS implements one as a shared memory?
|
|
|
|
|
Yes.
The way I understand it... when you post a WM_COPYDATA message, the kernel creates a temporary memory mapped file containing the bytes at the location specified relative to the senders address space. This memory mapped file is accessable to the recieving application. Upon SendMessage() returning the memory mapped file is marked for deletion.
Best Wishes,
Randor (David Delaune)
|
|
|
|
|
Hmm,... reading a few times what MSDN, I understood that you cannot return data in the buffer given by the sending application... but, since I've never tried myself, I would consider David's interpretation. Have already found some sample code on CP using such technique to share memory... 2 ways.
Well, it wouldn't be the first time when MSDN is missleading!
Still, the opinions found are divided almost 50-50. If you're planning to try it out, please let us know about your findings. It would be great if you can try it out on different OS versions.
While searching more info about it, I came across an interesting aspect:
http://www.flounder.com/wm_copydata.htm[^]
Hope you'll find this idea useful, and couldn't hurt using a GUID as explained there.
Best wishes,
|
|
|
|
|
hi all
i wana add my control icon into vc++ toolbox control. ex: i have my own button class drived from CButton. is there any way to put my button's icon in toolbox and than make vc++ ide to produce my button's source code? i mean the new button class will be drived from mybutton class. (sorry for my pure english )
thx much.
EmptyBox
|
|
|
|
|
Try Project --> Add to Project --> Components and Controls.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
thx DavidCrow.
i think it works in vc++ 6.0. does it work in 2003, too?
EmptyBox
|
|
|
|
|
eagle51 wrote: does it work in 2003, too?
I don't know. Mark Salsbery will have to answer that one.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
not sure if this is the right place, but i need a script to login and download some results on HyperTerminal. is there a script that can be used?
|
|
|
|
|
What are the best ways to send messages from one process to other process?
|
|
|
|
|
The "best" way depends on the message type/size/etc.
For messages between windows or threads that can fit in two INT_PTR-sized variables there's
PostMessage()/PostThreadMessage() (note you can't pass pointers).
For larger "messages" between windows there's the WM_COPYDATA message.
For anything else...
Interprocess Communications[^]
This episode brought to you by the letter N
|
|
|
|
|
What does a notepad open two similar process when invoked on a single file. What is the rational. It looks logical to do that when doing it over a network between two machines.
|
|
|
|
|
tom groezer wrote: What does a notepad open two similar process when invoked on a single file.
Like other text editors/word processors, Notepad does not actually keep the file open. Therefore, when opening the same file more than once, Notepad does not communicate with other instances of itself to see what they are doing.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Is there a way to set a size for message queue? Also is there any performance consideration to be made while selecting PeekMessage or GetMessage.
-- modified at 5:13 Sunday 8th July, 2007
|
|
|
|
|
tom groezer wrote: Is there a way to set a size for message loop?
loops have a size?
tom groezer wrote: is there any performance consideration to be made while selecting PeekMessage or GetMessage.
In a loop, yes. GetMessage() will wait for posted messages. PeekMessage() will not.
Looping calling PeekMessage() when no messages are available in the queue will use CPU time
needlessly.
Mark
This episode brought to you by the letter N
|
|
|
|
|
I think you can set a quota.
I am pretty sure the upper limit is 10,000 messages.
We have abandoned 'window message queues' in a few areas because of the limit.
Given the nature of your other queries, you might want to consider using TCP/IP or named pipes for your interprocess communications.
|
|
|
|
|
How could I achieve versioning of archive files.
|
|
|
|
|
The simplest way would be to insert a version number when storing (before writing anything else)
and when loading, extract the version number and use it to appropriately load the archive.
Mark
This episode brought to you by the letter N
|
|
|
|
|
I need to write a console application to write a state log. It will be executed as a task periodically and record the condition of things to a log file.
When I execute the application it causes the screen to flicker in the best of circumstances and a phantom console window to appear and disappear in the worst of circumstances even though I don’t write anything to the console. Everything is appended to a log file.
Is there any way of suppressing the flicker or phantom console window from appearing?
|
|
|
|
|
For similar problems I always recommend switching from a Console app to a Windows app and then not actually opening any Windows. Most of my test apps run that way.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
I was thinking about running a windows application instead of a console application but need to pass command line parameters. Is there a way to get the equivalent of the argv array when executing a windows app?
|
|
|
|
|
Check out the remarks section here: GetCommandLine()[^]
This episode brought to you by the letter Q
|
|
|
|
|
Mark Salsbery wrote: GetCommandLine()
Excellent! That along with Mathew's suggestion to use a windows application is just what I need to get rid of the flicker.
|
|
|
|