Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^4: [OT] Stats problem

by BrowserUk (Pope)
on Feb 27, 2015 at 12:23 UTC ( #1118069=note: print w/replies, xml ) Need Help??

in reply to Re^3: [OT] Stats problem
in thread [OT] Stats problem

That would certainly be advantageous in that it would allow you to definitively detect which address the overrun had occurred through.

The downside is that it adds another 4 bytes to the overhead for every allocation. Probably not a problem for a debug malloc library -- although one of the problems I had was that when I enabled the debug malloc, the program which was designed to run close to the limits of my physical memory without going into swapping, moved into swapping and ran like it was swimming n molasses as a result. So much so that I had to modify the parameters to reduce the memory usage to 1/4 to avoid swapping; which in turn meant that the problem I was trying to track down never actually occured.

The real advantage of the method I described is that it uses no extra space in actual allocation as it is only written to free space slots. Either when the virtual memory is first obtained; or when a pointer is freed. Of course, it will then only detect overruns if the happen to encounter a free slot; but with the advantage that they can remain enabled, at very little overhead, in production code.

I also had the notion of using two interleaving, free space chains. The first would be used, leaving (at least one) free space between all allocations, until it filled. Only then would the second be used. That might afford early(er) and more accurate detection of overruns.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

Replies are listed 'Best First'.
Re^5: [OT] Stats problem
by roboticus (Chancellor) on Feb 27, 2015 at 16:52 UTC


    Yeah, it can consume more memory. I always had a paragraph at the beginning, but the marker at the end was "free" roughly 1/4 of the time, since the allocator had to round up to the next paragraph anyway (MSVC 6.0, I don't know if it has the same strategy/constraints in newer versions).

    I really like the idea of two interleaved free chains to aid in detection. I noticed that in the applications I worked on, that allocation usually happened in just a few particular sizes, so allocating two blocks at a time (both of the same size) and dropping the second one into a free list might be interesting. I'll have to remember this when I do my next fun C/++ job.


    When your only tool is a hammer, all problems look like your thumb.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1118069]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2020-05-31 11:33 GMT
Find Nodes?
    Voting Booth?
    If programming languages were movie genres, Perl would be:

    Results (173 votes). Check out past polls.