473,320 Members | 2,073 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,320 software developers and data experts.

performance/style of memory allocation

Hi,

in program I have a frequently called function (~few times per second)
that needs a comparatively big amount of local memory (~10MB) for doing
its job.

Is it faster to make that memory static so it has not to be reallocated
all the time? Or is overall performance better if that memory is freed
when the function is done. Or is this no question of performance but
rather of style, then, what is considered nicer?

Thanks
Steffen

Jul 23 '05 #1
4 1348
Steffen wrote:
Is it faster to make that memory static so it has not to be reallocated
all the time? Or is overall performance better if that memory is freed
when the function is done.


I'm pretty sure it won't make a noticable difference in performance if
the function is only called a few times per second. The process heap
might get fragmented because of the multiple (de)allocations, though. It
all depends on the specifics of your application and platform, so it's
hard to say.

Regards
-Laurens
Jul 23 '05 #2
On Wed, 29 Jun 2005 13:00:28 +0400, Steffen <s.*********@gmx.de> wrote:
in program I have a frequently called function (~few times per second)
that needs a comparatively big amount of local memory (~10MB) for doing
its job.

Is it faster to make that memory static so it has not to be reallocated
all the time? Or is overall performance better if that memory is freed
when the function is done. Or is this no question of performance but
rather of style, then, what is considered nicer?


Why don't you just compare run times of both variants?

--
Maxim Yegorushkin
<fi****************@gmail.com>
Jul 23 '05 #3


Steffen wrote:
Hi,

in program I have a frequently called function (~few times per second)
that needs a comparatively big amount of local memory (~10MB) for doing
its job.
Luckily, today's Ghz processors can call functions
~millions times/second, and 10 MB isn't very much.
Is it faster ...


Don't worry about performance in the first iteration of
a program. Just put the object(s) you need on the stack.

If performance is a problem, get a profiler and find the
real culprit. Not earlier.

HTH,
Michiel Salters

Jul 23 '05 #4


msalters wrote:

[snip]
Don't worry about performance in the first iteration of
a program. Just put the object(s) you need on the stack.


OTOH, if you cannot allocate 10MB on the stack, you can pre-allocate
the memory and dispense it through some form of allocator interface.

The main problem with statically allocated memory is thread-safety, but
I don't know if this is relevant to your problem. /david

Jul 23 '05 #5

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

Similar topics

1
by: Bob | last post by:
Are there any known applications out there used to test the performance of the .NET garbage collector over a long period of time? Basically I need an application that creates objects, uses them, and...
11
by: Steve | last post by:
Hi, I'm using a std::vector to store a list of user defined objects. The vector may have well over 1000 elements, and I'm suffering a performance hit. If I use push_back I get a much worse...
15
by: Earl Higgins | last post by:
The company where I work as a Senior Software Engineer is currently revamping their (1991 era) "Programming and Style Guidelines", and I'm on the committee. The company, in business for over 20...
16
by: tweak | last post by:
When should malloc() and related functions (e.g. calloc(), realloc() ) be used? I keep hearing to keep stuff out of memory as much as possible since it's not as fast as when stuff is in the...
4
by: Nadav | last post by:
Hi, I hope this post will find it's way to some MS technical authority... I am experienced with bought Unmanaged C++ and Managed code ( C# ), There are some issues with the .NET framework that...
1
by: spiff | last post by:
We are migrating from VC++ 6 to VC++ 2003. It is a plain, unmanaged application with both C and C++ source. When running the debug build, even outside the debugger, the memory allocation/deallocation...
3
by: EasyKev | last post by:
We have been trying to upgrade all our C++ projects from VC6 to VS .Net2003 for a while (before VS 2005 arrived), and seem to be stuck now because of the performance degradation seen for the same...
66
by: Johan Tibell | last post by:
I've written a piece of code that uses sockets a lot (I know that sockets aren't portable C, this is not a question about sockets per se). Much of my code ended up looking like this: if...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.