Skip to main content
GameDev.net gamedev.net
🔒 Locked

Quick C++ question.

Started by vNistelrooy Apr 18, 2004 at 7:52 AM 5 replies 250+ views
Original Post
vNistelrooy
vNistelrooy
class C_A_Class_OMG
{
   void A_Function_OMG(void* Parameters_OMG);
};

C_A_Class_OMG *a=new C_A_Class_OMG;
How much RAM will a take?
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
mattd
mattd
1 byte?
vNistelrooy
vNistelrooy
quote:
Original post by mattd
1 byte?


It is 4byte at least because of the pointer, but does the functions add anything?



"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
mattd
mattd
No, because the functions aren't virtual. And since new must always attempt to return a valid pointer, even if 0 bytes are requested, it allocates 1 byte.

If you have MSVC, check malloc.c:

if (size == 0)
size = 1;


A will take up 4 bytes on the stack.

[edited by - mattd on April 18, 2004 9:06:34 AM]
vNistelrooy
vNistelrooy
I''m talking about VC++7. Oh well I guess I will have to check myself. >__<



"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"
vNistelrooy
vNistelrooy
quote:
Original post by mattd
No, because the functions aren''t virtual. And since new must always return a valid pointer, even if 0 bytes are requested, it allocates 1 byte.

If you have MSVC, check malloc.c:

if (size == 0)
size = 1;


A will take up 4 bytes on the stack.


Thank you.



"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

Topic Locked

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

Sign in to reply to this topic.