473,503 Members | 11,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic Memory allocation issue

9 New Member
As per my knowledge i know that when a structure is defined, no memory is assigned to its members but when a variable of that structure is declared memory is allocated and also this allocation takes place at runtime. Now my issue is that how is dynamic memory allocation different in case of structures(when variable of that structure is declared) and classes(where memory is allocated dynamically using new operator). whats the difference it both the allocation?

Now lets say i have a structure as shown below:-
struct abc
{
int a;
char str[10];
};
at this point memory is not allocated to a and str. It'll be allocated only if i do the following:-

struct abc var;
where var is a variable of type struct.
Now my question is how exactly the MEMORY IS ALLOCATED to structure members a and str? Is that similar to that allocated using new operator in case of class or different? Will it use stack or heap?
Aug 14 '06 #1
2 2393
Banfa
9,065 Recognized Expert Moderator Expert
Depends where you declare var. It will be allocated in exactly the same way as memory is allocated to an int variable, this could be off the heap or stack or in fact somewhere else entirely depending on the platform and how the variable is declared.

It is not new'd/malloc'd and must not have be delete'd/free'd
Aug 14 '06 #2
nayannovellus
9 New Member
Thanks banfa...:)
Aug 16 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2563
by: Franklin Lee | last post by:
Hi All, I use new to allocate some memory,even I doesn't use delete to release them. When my Application exit, OS will release them. Am I right? If I'm right, how about Thread especally on...
6
8183
by: chris | last post by:
Hi all, I need to know, what is the difference between dynamic memory allocation, and stack allocation ? 1. If I have a class named DestinationAddress, when should I use dynamic memory...
6
2379
by: Sandeep Chikkerur | last post by:
Hi, If the entire heap memory for dynamic allocation is not available, does the compiler always return NULL ? eg: char *s; s = (char *)malloc(...);
11
3026
by: toton | last post by:
Hi, I have little confusion about static memory allocation & dynamic allocation for a cluss member. I have class like class Bar{ public: explicit Bar(){ cout<<"bar default"<<endl; }
24
19035
by: Ken | last post by:
In C programming, I want to know in what situations we should use static memory allocation instead of dynamic memory allocation. My understanding is that static memory allocation like using array...
1
7945
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was...
3
2946
by: ranjeetasharma81 | last post by:
Hi all, I have a big C-cod, in which there are lots of dynamic memory allocation used. I want to replace dynamic memroy allocation by static arrays. The following are the problems that i am...
14
3812
by: vivek | last post by:
i have some doubts on dynamic memory allocation and stacks and heaps where is the dynamic memory allocation used? in function calls there are some counters like "i" in the below function. Is...
10
4380
by: swornavidhya.mahadevan | last post by:
Which allocation (Static / Dynamic) is suitable for the situation when we are trying to allocate for a overloaded memory when the memory is full and no space to allocate. What will happen if both...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7095
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7361
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7015
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5602
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
749
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.