my little implementation of malloc

C

Chris Dollin

jacob said:
I agree with that. How can one write an allocator
without calling the OS?

[With pen and paper, of course ...]

enum { HEAPSIZE = 10 * 1024 * 1024 };

static char heap[HEAPSIZE];

(fx:insertCodeHere)
 
R

Richard Bos

Keith said:
Then say so. The word "Nazi" is highly offensive to many people.
allright. :]
But some people seem to take some things too seriously sometimes...

And some don't take them seriously enough. Have you ever met anyone
whose family was persecuted in WW II? What would you say if I called you
a Klansman, or an Al-Qaedist? You'd be angry, and rightly so. Don't do
the same thing, and don't make the mistake of thinking that the Nazis
are a problem of history. They are, unfortunately, still with us, under
different names.

Richard
 
R

Richard Heathfield

Richard Bos said:
Keith said:
Then say so. The word "Nazi" is highly offensive to many people.
allright. :]
But some people seem to take some things too seriously sometimes...

And some don't take them seriously enough. Have you ever met anyone
whose family was persecuted in WW II?

I have. My wife's family was amongst those who suffered under the Nazis.
This is not a matter of ancient history, but of living memory.
[The Nazis] are, unfortunately, still with us, under
different names.

And equally unfortunately, they have a large pool of disaffected young
people from which to draw support.
 
N

Nick Keighley

hey, don't be nazi. you NEED to call system to do memory management.
Point of this topic is to demonstrate his handler, and it is impossible
without.

well you *could* statically allocate a large block of memory and then
use that as a heap. If the platform doesn't support dynamic memory
allocation
this may even be sane.
And it's enough to support one OS in demonstration, win32 is a
good choice because most asmers use it.

"asmers"?


--
Nick Keighley

De maan likt niet hoog The moon doesn't look high
Maar het is niet zo But it is not so
De maan is wel hoog The moon is very high
Of niet sams? Or is it?
 
V

vid512

CBFalconer said:
Pointless, because the original allocator knows how much he
requested. No need to save it.
i do provide call to retrieve size of allocated block. Then, i find it
nescessary to return original size. I also have "realloc" call, which
in one version zeroes all added memory. In such case, this *is*
nescessary.
With the 'SAVEMEMORY' or something defeated, there are signatures
in nmalloc blocks. They involve expanding the overhead per
allocation from 16 to 24 bytes.
in my case, i use "size" as both size of block and kind-of pointer to
next block, so i save 4 bytes here. Also I don't have nextfree and
prevfree (but am thinking about adding them), so it's 16 bytes for me.
- it doesn't have speed-ups like yours freehdrs[] array... maybe
i will steal this idea in future ;)

also, you can easily catch out-of-heap pointers instead of causing
crash... just ensure they are in range <heapptr, heapptr+heapsize)
before accessing them.

Where a crash is forced, it is known that the memory arena has been
fouled, and there is no way to recover. Otherwise the user can
control the actions of signal and raise.
I prefer returning error describing what happened. "Internal Error:
Invalid pointer" looks little better than "Core dumped" to me.
There is no such thing as
a range and heapsize, since there may well be multiple 'heaps' in
use. that is up to the actual action of sbrk. I think sbrkbgn is
the thing that keeps track of multiple heaps. All this, except the
use of sbrk, is fully standard C outside of the assumption of
arithmetic on the pointers.
sorry, i thought you use just single block.
No such routine in standard C. It is up to the compiler to decide
what instructions to use.
if you don't have to support too many compilers with your code, it's
sometimes better to aid compiler a little in it's job.
 
V

vid512

And some don't take them seriously enough. Have you ever met anyone
whose family was persecuted in WW II?
I knew this would come... sure, for such people it would be too hard.
But it's 60 years over, and we cannot keep tabooing it forever. If we
would judge words based on victims, all of these would be pretty
offensive words: "monarch", "legionairy", "communist", "capitalist",
"christian", "pagan", "colonist"... some of these worser than "nazi".

by the way: i did. My grandfather was in forced-work camp for 3 month
until he escaped.
What would you say if I called you a Klansman, or an Al-Qaedist?
You'd be angry, and rightly so.
No, i wouldn't. Especially if you would do it in phrase-like style
like i tried to do.
Don't do the same thing, and don't make the mistake of thinking that the Nazis
are a problem of history. They are, unfortunately, still with us, under
different names.
I don't think they have some real political influence now, with all
the propaganda. With all the anti-nazi propaganda these days, you can
be thinking just like they did, and hate them at the same time. I
would personally teach people much more about nazi theories, so
everyone can see how stupid it was.
 
R

Richard Bos

[ Don't over-snip attribution lines, please. ]
I don't think they have some real political influence now, with all
the propaganda. With all the anti-nazi propaganda these days, you can
be thinking just like they did, and hate them at the same time. I
would personally teach people much more about nazi theories, so
everyone can see how stupid it was.

It keeps amazing me how naive children these days are.

Richard
 
V

vid512

Richard said:
It keeps amazing me how naive children these days are.

Examples please? In what countries does people believe in arian race
that is descendant of atlantic civilization? In what country people
believe jews were resons for bad school system in germany in '30s? How
many people you hear mentioning Wotan when speaking about religion? Or
when is the last time you heard about "positive christianism"?

don't forget, "nazism" != "fascism"
 
F

Frank Kotler

Betov said:
"(e-mail address removed)" <[email protected]> écrivait





Really? What of Isreal?

I suppose you mean Israel...
USA? China? To name just a few of them.

http://www.americannaziparty.com/about/index.php says:

"...the two main tenants [sic] of National Socialism embodies [sic] the
Struggle for Aryan Racial survival, and Social Justice for White Working
Class people throughout our land."

(I assume these people are of the "You're in America, speak English!"
persuasion. They could use some work.)

Does the Chinese Nazi party have the same goals? How about the Israeli
Nazi party? What's your definition of "Nazi", such that these three
countries fit into it? If we want it to "never happen again", we better
figure out what it is we want to not happen!!!

Best,
Frank
 
A

Al Balmer

Would the participants in this thread please do one or more of the
following?

1. Delete comp.lang.c from the distribution list.
2. Change the subject line.
3. Add [OT] to the subject line.
 
M

Mark McIntyre

Examples please?

Check out the British National party sometime. And find out which
european country elected an ex-stormtrooper a President in 1986. And
which one had to keep its ministers home because the other nations
wouldn't talk to them.
don't forget, "nazism" != "fascism"

Sure, there's plenty of other fascists. So what?
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top