Skip to main content
gamedev.net
🔒 Locked

Question about Pointers

Started by FrancoisSoft Sep 3, 2003 at 5:02 PM 6 replies 300+ views
Original Post
FrancoisSoft
FrancoisSoft
Ok, when I allocate a buffer from the heap I usually try to use the sizeof operator to take the size of the buffer but I only get 4 when the buffer may be 1000 bytes in size. Why can''t I use sizeof on buffers allocated from the heap but I can use them on buffer allocated from the stack? Hey, don''t forget to visit my page... by clicking here!
drekkar
drekkar
4 is the size of the pointer, not the memory it is pointing to
antareus
antareus
sizeof is evaluated at compile time, not runtime.

If you want someone to keep track of how big your buffers are then you should be using a std::vector.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
JonStelly
JonStelly
Or you could override the new operator and implement some sort of allocation tracking, but chances are that if you need something like that, you''re doing something else wrong.
FrancoisSoft
FrancoisSoft
quote:
Original post by JonStelly
Or you could override the new operator and implement some sort of allocation tracking, but chances are that if you need something like that, you''re doing something else wrong.


I don''t think I want to do this.


Hey, don''t forget to visit my page... by clicking here!
Ready4Dis
Ready4Dis
Well, just store the size that you''re allocating in a variable.. obviuosly you know the size that you are allocating, and the size of the data type that you''re allocating, so you know how much memory it''s using.
antareus
antareus
Problem is the token type should be outside the allowable range of values. This leads to silliness like a member function called getchar returning an int because it has to express failure somehow.

*cough* exceptions people, exceptions*cough*
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.