473,385 Members | 1,983 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

What is the solution..?

Hi,

Its said that one should avoid dynamic allocation of memory, as it de-
fragment the memory into small chunks and allocation of memory is a
costly process in terms of efficiency. So what is the best solution to
handle to situation in which we need to allocate memory at run time.
Regards
Mayank Jain(Nawal)
co***************@gmail.com
9818390836

Aug 20 '07 #1
12 2346
<co***************@gmail.comwrote in message
news:11**********************@i38g2000prf.googlegr oups.com...
Hi,

Its said that one should avoid dynamic allocation of memory, as it de-
fragment the memory into small chunks and allocation of memory is a
costly process in terms of efficiency. So what is the best solution to
handle to situation in which we need to allocate memory at run time.
using dynamic allocation of memory. use new
Aug 20 '07 #2
On Aug 20, 9:32 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
<contactmayankj...@gmail.comwrote in message

news:11**********************@i38g2000prf.googlegr oups.com...
Hi,
Its said that one should avoid dynamic allocation of memory, as it de-
fragment the memory into small chunks and allocation of memory is a
costly process in terms of efficiency. So what is the best solution to
handle to situation in which we need to allocate memory at run time.

using dynamic allocation of memory. use new
How new is going to solve my problem. Are you trying to say use new
instead of malloc for allocating memory?
Regards
Mayank Jain(Nawal)
co***************@gmail.com
9818390836

Aug 20 '07 #3
On 2007-08-20 18:21, co***************@gmail.com wrote:
Hi,

Its said that one should avoid dynamic allocation of memory, as it de-
fragment the memory into small chunks and allocation of memory is a
costly process in terms of efficiency. So what is the best solution to
handle to situation in which we need to allocate memory at run time.
It depends on the situation, there is no perfect solution that will work
in all situations. I think that the advice is rather that one should
prefer automatic storage over dynamic when possible. However, one should
be aware that using automatic storage is not possible in all cases, in
fact most non-trivial applications will make use of dynamic memory,
either directly or indirectly via containers.

For some applications were objects of a certain kind needs to be
allocated and deallocated frequently a pool-allocator might increase the
performance and the effects of fragmentations is lessened.

--
Erik Wikström
Aug 20 '07 #4
<co***************@gmail.comwrote in message
news:11**********************@i38g2000prf.googlegr oups.com...
Hi,

Its said that one should avoid dynamic allocation of memory, as it de-
fragment the memory into small chunks and allocation of memory is a
costly process in terms of efficiency. So what is the best solution to
handle to situation in which we need to allocate memory at run time.
Dynamic allocation is the ONLY solution to allocating memory at run time
(unless you use a language that provides garbage collection). If you have
problems with fragmentation then the only thing you can do is smarter
dynamic allocation, which requires knowledge of the allocation requirements
of your application.

Aug 20 '07 #5
On Aug 20, 9:49 pm, "Scott McPhillips [MVP]" <org-dot-mvps-at-
scottmcpwrote:
<contactmayankj...@gmail.comwrote in message

news:11**********************@i38g2000prf.googlegr oups.com...
Hi,
Its said that one should avoid dynamic allocation of memory, as it de-
fragment the memory into small chunks and allocation of memory is a
costly process in terms of efficiency. So what is the best solution to
handle to situation in which we need to allocate memory at run time.

Dynamic allocation is the ONLY solution to allocating memory at run time
(unless you use a language that provides garbage collection). If you have
problems with fragmentation then the only thing you can do is smarter
dynamic allocation, which requires knowledge of the allocation requirements
of your application.
What are the smarter way of allocating memory. I know the time and all
details about the memory requirement of my application. So how can it
help me in improving the efficiency of my code. Can you write a sample
code for this.
What is pool allocator?
Regards
Mayank Jain(Nawal)
co***************@gmail.com
9818390836

Aug 20 '07 #6
On Aug 20, 11:56 am, "contactmayankj...@gmail.com"
<contactmayankj...@gmail.comwrote:
On Aug 20, 9:49 pm, "Scott McPhillips [MVP]" <org-dot-mvps-at-

scottmcpwrote:
<contactmayankj...@gmail.comwrote in message
news:11**********************@i38g2000prf.googlegr oups.com...
Hi,
Its said that one should avoid dynamic allocation of memory, as it de-
fragment the memory into small chunks and allocation of memory is a
costly process in terms of efficiency. So what is the best solution to
handle to situation in which we need to allocate memory at run time.
Dynamic allocation is the ONLY solution to allocating memory at run time
(unless you use a language that provides garbage collection). If you have
problems with fragmentation then the only thing you can do is smarter
dynamic allocation, which requires knowledge of the allocation requirements
of your application.

What are the smarter way of allocating memory. I know the time and all
details about the memory requirement of my application. So how can it
help me in improving the efficiency of my code. Can you write a sample
code for this.
What is pool allocator?
Regards
Mayank Jain(Nawal)
contactmayankj...@gmail.com
9818390836- Hide quoted text -

- Show quoted text -

I can answer this for you. Can you put me in touch with your
employer, so he can redirect your paychecks to me as well?

Aug 20 '07 #7
co***************@gmail.com wrote:
Hi,

Its said that one should avoid dynamic allocation of memory, as it de-
fragment the memory into small chunks and allocation of memory is a
costly process in terms of efficiency. So what is the best solution to
handle to situation in which we need to allocate memory at run time.
Why do you think it is a concern? Has this caused problems in your
current project?


Brian
Aug 20 '07 #8
co***************@gmail.com wrote:
:: On Aug 20, 9:32 pm, "Jim Langston" <tazmas...@rocketmail.com>
:: wrote:
::: <contactmayankj...@gmail.comwrote in message
:::
::: news:11**********************@i38g2000prf.googlegr oups.com...
:::
:::: Hi,
:::
:::: Its said that one should avoid dynamic allocation of memory, as
:::: it de- fragment the memory into small chunks and allocation of
:::: memory is a costly process in terms of efficiency. So what is
:::: the best solution to handle to situation in which we need to
:::: allocate memory at run time.
:::
::: using dynamic allocation of memory. use new
::
:: How new is going to solve my problem. Are you trying to say use new
:: instead of malloc for allocating memory?

He is saying that you should use new (and not malloc) to allocate
dynamic memory, if you need to do that. If you don't need dynamic
memory, you shouldn't allocate any.

The meaning of 'avoid' is "don't do it, unless you have to", not
"never do it".
Bo Persson
Aug 20 '07 #9

co***************@gmail.com wrote:
What is pool allocator?
Go to http://www.boost.org. They have some
implementations for pool allocators and explanations
of what it is.

Regards,

Werner

Aug 20 '07 #10
<co***************@gmail.comwrote in message
news:11*********************@i13g2000prf.googlegro ups.com...
What are the smarter way of allocating memory. I know the time and all
details about the memory requirement of my application. So how can it
help me in improving the efficiency of my code.
There are decades of research on this. You could start with a Google search
for "low fragmentation heap"

Aug 20 '07 #11
On Mon, 20 Aug 2007 16:21:51 -0000, "co***************@gmail.com"
<co***************@gmail.comwrote in comp.lang.c++:
Hi,

Its said that one should avoid dynamic allocation of memory, as it de-
fragment the memory into small chunks and allocation of memory is a
costly process in terms of efficiency. So what is the best solution to
handle to situation in which we need to allocate memory at run time.
"It is said..." by whom? What makes you think this mysterious third
person source of information is correct?

If you do think this anonymous source is correct, ask he/she/it for
recommendations.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Aug 21 '07 #12
On Aug 21, 1:49 am, "Scott McPhillips [MVP]" <org-dot-mvps-at-
scottmcpwrote:
Dynamic allocation is the ONLY solution to allocating memory at run time
(unless you use a language that provides garbage collection).
Getting there. I would argue that dynamic allocation IS - by the very
meaning of the word dynamic - allocation at run-time. It's not just
the only solution, it is indivisibly the thing itself. "garbage
collection" only refers to one aspect of the myriad design and
implementation choices for algorithms offering dynamic memory
management.
If you have
problems with fragmentation then the only thing you can do is smarter
dynamic allocation, which requires knowledge of the allocation requirements
of your application.
Precisely.

Mayank: what's good depends a lot on the patterns of memory usage.

There are a couple distinct aspects.

Firstly: there's how often you need to do allocations. For example,
if you are having trouble inserting millions of elements in a
container, then see if there are functions to preallocate the required
space rather than grow during insertions, or at least to resize more
aggressively (e.g. resize arrays or hash tables by x4 instead of x2
each time more space is needed). How much can be done depends on the
container: for example, linked lists aren't likely to allow any kind
of pre-allocation.

Secondly: you can decrease the time needed for the allocations you
really can't avoid. To do this, follow suggestions elsewhere in this
thread, and use a custom allocator from boost.

So, to work out which direction to head down, you should profile your
application and work out which containers are causing you trouble,
during what kind of operations (insert, lookup, erase).

Taking a step back, in your original post:
Its said that one should avoid dynamic allocation of memory, as it de-
fragment the memory into small chunks and allocation of memory is a
costly process in terms of efficiency. So what is the best solution to
handle to situation in which we need to allocate memory at run time.
"It's said" suggests even looking at memory allocation may be a path
you've started on with no clear evidence from actual profiling. Did
someone at work tell you "this things slow, think it's the memory
allocation", and ask you to fix it? Don't believe them unless you see
hard evidence in the form of profiling results: you'll waste a lot of
time.

Cheers,

Tony

Aug 21 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
26
by: Lasse Edsvik | last post by:
Hello I'm trying to build a simple COM+ app in vs.net using C# and i cant register it in component manager..... what more is needed than this: using System; using...
9
by: seberino | last post by:
I have been using distuils for a while and was wondering when Python Eggs (new project) is better? So basically Python Eggs precompiles and compresses binaries for you so you just have to load...
4
by: Steve Barnett | last post by:
I copied and paste a form in my solution and renamed the copy (all done in the solution explorer) and now, when I compile the app, I get the following error: ----------- The item...
8
by: Connectcase | last post by:
Hi there, and greetings from the Netherlands. Trying to switch over from VB to VB.NET and struggling with something that seemed very simple: ============================ Public Class Form1...
3
by: Mark Poppers | last post by:
I found a *.sln and an *.suo file which belong to my current project because the have the same name "TestDatabase33....." as my project. What is the purpose of these files ? If I delete them...
2
by: Paul Elliott | last post by:
How are parameterized translation strings commonly handled? Suppose I need to create a string like: "file %1 failed to open", where %1 exists at runtime, but I need to create it in a way that...
5
by: Fred Hebert | last post by:
I was thinking of switching to VS2005, so I sent off for and received a 120 evaluation kit. This version was supposed to be the same as the full version, but the key limits you to 120 days. I...
8
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi I've just come back to a project I've had a week or so off from, haven't touched it, and it seemed to be working fine when I left it. However, it's not compiling!! Here's the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.