473,771 Members | 2,372 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic allocation to static memory allocation

2 New Member
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 facing:

1- From structure and dynamic memory allocation point of view, the code is
very complicated. The code has various “nested structures” with a number
of levels. The size of memory allocated for pointer to structure or its
pointer structure member is calculated at “run time”. That size may vary
at different modes.
2- Different levels of structure are being allocated memory at different
places within the code.
3- If we consider any structure, there are two possibilities:
a) It is used as a part of any other structure, or
b) Different individual pointers of type structure are defined, which are being allocated memory at different places with different sizes (which may again in turn vary for different modes) that are calculated at run time. Since size is adaptive, it is very difficult to calculate the minimum size required to be llocated for each structure and array. Is there any software available to do so??

Even if we are able to find the size and allocate the maximum size to different structure and its member, it will be not be the optimum utilization of memory since at the moment in the code, the minimum required memory is calculated every time and only that much is allocated. But one of my senior ask me to do so. Is it going to be benificial some how??

The process seems to be quite complicated and I dont know where to start with and how. I am very confused. Any help will be appriciated .

Thanks
Ranjeeta
May 4 '07 #1
3 2996
ajayraj
21 New Member
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 facing:

1- From structure and dynamic memory allocation point of view, the code is
very complicated. The code has various “nested structures” with a number
of levels. The size of memory allocated for pointer to structure or its
pointer structure member is calculated at “run time”. That size may vary
at different modes.
2- Different levels of structure are being allocated memory at different
places within the code.
3- If we consider any structure, there are two possibilities:
a) It is used as a part of any other structure, or
b) Different individual pointers of type structure are defined, which are being allocated memory at different places with different sizes (which may again in turn vary for different modes) that are calculated at run time. Since size is adaptive, it is very difficult to calculate the minimum size required to be llocated for each structure and array. Is there any software available to do so??

Even if we are able to find the size and allocate the maximum size to different structure and its member, it will be not be the optimum utilization of memory since at the moment in the code, the minimum required memory is calculated every time and only that much is allocated. But one of my senior ask me to do so. Is it going to be benificial some how??

The process seems to be quite complicated and I dont know where to start with and how. I am very confused. Any help will be appriciated .

Thanks
Ranjeeta
Please mention the compiler you are using?
May 4 '07 #2
ranjeetasharma81
2 New Member
Hi,

My compiler is Microsoft Visual C++ 6.0.

Thanks
May 7 '07 #3
ajayraj
21 New Member
Hi,

My compiler is Microsoft Visual C++ 6.0.

Thanks
Then you can use the tool available here
http://www.codeproject .com/tools/leakfinder.asp
its actually for finding the memory leak of the code,
but u can get the status of the heap allcation too.
So try it out.
It will help you.
May 8 '07 #4

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

Similar topics

6
8213
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 allocation to create object of that class ? 2. If it says "dynamic memory allocation", is it mean the following code : DestinationAddress* dest = new DestinationAddress(); // code 1
5
3760
by: swarsa | last post by:
Hi All, I realize this is not a Palm OS development forum, however, even though my question is about a Palm C program I'm writing, I believe the topics are relevant here. This is because I believe the problem centers around my handling of strings, arrays, pointers and dynamic memory allocation. Here is the problem I'm trying to solve: I want to fill a list box with a list of Project Names from a database (in Palm this is more...
13
4723
by: xian_hong2046 | last post by:
Hello, I think dynamic memory allocation is supposed to be used when one doesn't know in advance how much memory to allocate until run time. An example from Thinking in C++ is to dynamically create an array (using "new") since one doesn't know it size when writing the program. However, it looks to me that the size information must come from somewhere at run time, and this information can be passed to array creation function as a...
11
3054
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
19094
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 is faster than malloc, but dynamic memory allocation is more flexible. Please comment... thanks.
7
8224
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
1
7976
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 compiled and run without any erros but the second program has a run time error when the function return from allocate and the ptr become NULL. How to fixed this? Second Program: /* Best Method to allocate memory for 2D Array because it's ...
14
3837
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 this stored in stack. If yes whether it will be deleted on exiting from the function. is dynamic memory allocation needed for this purpose
10
4429
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 the allocation is impossible. Sworna vidhya
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10103
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9911
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8934
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2850
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.