Click here to Skip to main content
15,914,417 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: StayOnTop for window. Pin
Christian Graus22-Oct-02 13:44
protectorChristian Graus22-Oct-02 13:44 
GeneralRe: StayOnTop for window. Pin
Anonymous23-Oct-02 4:31
Anonymous23-Oct-02 4:31 
GeneralRe: StayOnTop for window. Pin
Paul M Watt22-Oct-02 14:13
mentorPaul M Watt22-Oct-02 14:13 
GeneralRe: StayOnTop for window. Pin
Christian Graus22-Oct-02 15:34
protectorChristian Graus22-Oct-02 15:34 
GeneralC++ Memory Allocation and Memory Leakage Pin
Anonymous22-Oct-02 13:15
Anonymous22-Oct-02 13:15 
GeneralRe: C++ Memory Allocation and Memory Leakage Pin
Christian Graus22-Oct-02 13:30
protectorChristian Graus22-Oct-02 13:30 
GeneralRe: C++ Memory Allocation and Memory Leakage Pin
Paul Oss22-Oct-02 13:38
Paul Oss22-Oct-02 13:38 
GeneralRe: C++ Memory Allocation and Memory Leakage Pin
Paul M Watt22-Oct-02 13:45
mentorPaul M Watt22-Oct-02 13:45 
The amount of memory in the free store really depends on your memory manager. When you call new, the default memory manager is the C-runtime libraries. These libraries allocate a page of memory, and then dish out pointers to you as you need it. When you call delete that memory is returned to the store. It really does not matter how much memory is available in the store as you could use a memory manager that does things completely differently. In fact you could write your own memory manager and over load the new operator to faciliate this yourself.

What I would recommend is that you become very comfortable with the interface that C++ has supplied to allocate memory (new and delete) and move on from there.

C++ does not really supply a clean way to report how much memory has been allocated to a specific pointer. It is up to the developer to manage these sizes. If you allocate memory for an array of bytes with new like this:

<br />
new BYTE[100];<br />


you will get 100 bytes. If you want to pass that pointer to a function call, and that function needs to know how much memory is in that buffer, you will need to pass the 100 in as well.

Objects created on the stack can use the sizeof() operator. This is a compile time feature that will report the number of bytes in a particular object or variable. But beware if you try this:

<br />
Object *obj = new Object;<br />
int size = sizeof(obj);<br />


size will equal 4 (or the size of the pointers on your system), because you are requesting the size of the pointer to the object rather than the object itself.

Like Christian already posted, if you dont want to leak memory, then make sure you match each new with a delete, and each new[] with a delete[]. There are tricks however to help your memory management work a little smoother. C++ has a few template classes called auto_ptr or smart pointers. Another technique that you may want to look into is reference counting. This is a technique that COM uses exensively.

I hope I answered some of your questions, I am not quite sure what all of them were. If you have any others feel free to ask.

Good luck


Build a man a fire, and he will be warm for a day
Light a man on fire, and he will be warm for the rest of his life!

GeneralRe: C++ Memory Allocation and Memory Leakage Pin
Christian Graus22-Oct-02 15:35
protectorChristian Graus22-Oct-02 15:35 
GeneralRe: C++ Memory Allocation and Memory Leakage Pin
ursus zeta23-Oct-02 9:47
ursus zeta23-Oct-02 9:47 
QuestionTracking ToolTips in a CControlBar? Pin
Jim A. Johnson22-Oct-02 12:58
Jim A. Johnson22-Oct-02 12:58 
AnswerRe: Tracking ToolTips in a CControlBar? Pin
Maximilien22-Oct-02 15:13
Maximilien22-Oct-02 15:13 
GeneralViews Pin
Anonymous22-Oct-02 12:56
Anonymous22-Oct-02 12:56 
GeneralRe: Views Pin
Ben Burnett22-Oct-02 14:13
Ben Burnett22-Oct-02 14:13 
GeneralHide the Windows Clock Pin
alpha+22-Oct-02 12:52
alpha+22-Oct-02 12:52 
GeneralDialogBox Pin
G. White22-Oct-02 12:37
G. White22-Oct-02 12:37 
GeneralRe: DialogBox Pin
Paul M Watt22-Oct-02 12:46
mentorPaul M Watt22-Oct-02 12:46 
GeneralRe: DialogBox Pin
Christian Graus22-Oct-02 13:19
protectorChristian Graus22-Oct-02 13:19 
QuestionTerminating window-less process? Pin
Abin22-Oct-02 12:29
Abin22-Oct-02 12:29 
AnswerRe: Terminating window-less process? Pin
Hans Ruck22-Oct-02 23:41
Hans Ruck22-Oct-02 23:41 
Generaloverloaded operator new and STL vector Pin
Nemanja Trifunovic22-Oct-02 12:30
Nemanja Trifunovic22-Oct-02 12:30 
GeneralRe: overloaded operator new and STL vector Pin
Christian Graus22-Oct-02 13:34
protectorChristian Graus22-Oct-02 13:34 
GeneralRe: overloaded operator new and STL vector Pin
Nemanja Trifunovic22-Oct-02 15:58
Nemanja Trifunovic22-Oct-02 15:58 
GeneralRe: overloaded operator new and STL vector Pin
Christian Graus22-Oct-02 16:01
protectorChristian Graus22-Oct-02 16:01 
GeneralRe: overloaded operator new and STL vector Pin
Nemanja Trifunovic22-Oct-02 16:10
Nemanja Trifunovic22-Oct-02 16:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.