Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > malloc() execution time?

Reply
Thread Tools

malloc() execution time?

 
 
Keith Thompson
Guest
Posts: n/a
 
      12-30-2009
http://www.velocityreviews.com/forums/(E-Mail Removed) writes:
[...]
> I've gone over the code and am pretty certain that I'm not
> copying the maximum characters, but rather only those that
> are used. However, I am setting a maximum line length and
> having an array of those.


You've gone over the code, but we haven't been able to. Please post
it.

> Thanks for all your responses; I'm happy with the notion
> that while you'd normally expect malloc to be slower, it
> won't always be. I was just quite surprised by it.


There's probably a good reason for the difference in performance, but
we just don't have enough information to guess what it might be.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
 
Kaz Kylheku
Guest
Posts: n/a
 
      12-31-2009
On 2009-12-30, (E-Mail Removed) <(E-Mail Removed)> wrote:
> In other words, the malloc() version ran faster. Both were
> run on the same file, of course, which was of almost the
> maximum size permitted by the program (4999 lines).


Try aligning the string buffers carved from the array to at least
a four byte boundary.
 
Reply With Quote
 
 
 
 
Kaz Kylheku
Guest
Posts: n/a
 
      12-31-2009
On 2009-12-31, Kaz Kylheku <(E-Mail Removed)> wrote:
> On 2009-12-30, (E-Mail Removed) <(E-Mail Removed)> wrote:
>> In other words, the malloc() version ran faster. Both were
>> run on the same file, of course, which was of almost the
>> maximum size permitted by the program (4999 lines).

>
> Try aligning the string buffers carved from the array to at least
> a four byte boundary.


Another thing.

Learn about the tool called ``oprofile'' and install it. It requires a
kernel module and some software tools.

A profiler can tell you where your program is spending its time. You
can find out out much percentage of your program's time is really spent
in malloc versus elsewhere.
 
Reply With Quote
 
Nobody
Guest
Posts: n/a
 
      12-31-2009
On Wed, 30 Dec 2009 02:18:00 +0000, dgoodmaniii wrote:

> I have a question about execution speed between allocating
> storage dynamically with malloc() and doing so statically
> with arrays. Which is faster?


The latter. Of course, this isn't specified by the standard, but it's
almost invariably true in practice (the "almost" being that there will
always be obscure platforms which behave in a radically different matter
to the mainstream).

The absolute worst plausible case is that a static array *might* be as
slow as malloc(), but this is unlikely. It will typically be substantially
faster, particularly if the array isn't so large that it dominates the
process' memory consumption.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
private data stashed in local/global execution context of PyEval_EvalCode disappears down the execution stack sndive@gmail.com Python 9 11-14-2007 10:31 PM
To Know bat file, execution is completed using VB.NET =?Utf-8?B?TXVzdGFx?= ASP .Net 1 06-23-2005 01:00 PM
What is firefox execution command for 1.0 in Linux Al. C Firefox 3 01-19-2005 05:08 AM
How to display progress bar in windows form during execution of DTS package? owais ASP .Net 1 10-05-2004 09:11 PM
Dynamic Execution of Function/Proc Kishor ASP .Net 9 09-27-2003 05:53 AM



Advertisments