[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-users] Re: [lwip] Proposal for magic numbers in LwIP
From: |
Adam Dunkels |
Subject: |
[lwip-users] Re: [lwip] Proposal for magic numbers in LwIP |
Date: |
Thu, 09 Jan 2003 01:30:01 -0000 |
Hi!
On Wednesday 19 June 2002 20.25, you wrote:
> I propose that all structures which are dynamically allocated
> begin with a magic number. Before the structure is free'd this
> number should be set to zero. My own practice is:
>
> s = nalloc();
> memset (s, 0, sizeof (*s));
> s->magic = THE_MAGIC_OF_S;
>
> ....
>
> s->magic = 0;
> free (s);
A good idea! What about wrapping it up in a macro that could be null #defined
when compiled without debugging? Like this:
s = mem_malloc();
DEBUG_SETMAGIC(s, S_MAGIC_NUMBER);
DEBUG_SETMAGIC(s, 0);
mem_free(s);
... and
DEBUG_CHEKCMAGIC(s, S_MAGIC_NUMBER);
/adam
--
Adam Dunkels <address@hidden>
http://www.sics.se/~adam
[This message was sent through the lwip discussion list.]