Re: Questions regarding specialized malloc()/free() replacements
- From: blargg.h4g@xxxxxxxxxxxxx (blargg)
- Date: Sun, 04 Jan 2009 08:38:51 -0600
Stephan Beal wrote:
blargg wrote:[...]
[...]void MyType_init()
[...]void MyType_free( MyType* p )
{
/* This might be technically non-portable, though portable in
practice */
if ( p != NULL && (void*) p >= blocks &&
(void*) p < blocks += max_blocks )
Why shouldn't this be portable? An array must, by definition, be a
contiguous range of memory, which means that any memory from outside
that range *must* compare not-equal.
Equal, not equal, sure, but the others require that the pointers be
inside the same object:
| 6.5.8 Relational operators
[...]
| 5 When two pointers are compared, the result depends on the relative
| locations in the address space of the objects pointed to. If two
| pointers to object or incomplete types both point to the same object,
| or both point one past the last element of the same array object, they
| compare equal. If the objects pointed to are members of the same
| aggregate object, pointers to structure members declared later compare
| greater than pointers to members declared earlier in the structure,
| and pointers to array elements with larger subscript values compare
| greater than pointers to elements of the same array with lower
| subscript values. All pointers to members of the same union object
| compare equal. If the expression P points to an element of an array
| object and the expression Q points to the last element of the same
| array object, the pointer expression Q+1 compares greater than P. In
| all other cases, the behavior is undefined.
.
- References:
- Questions regarding specialized malloc()/free() replacements
- From: Stephan Beal
- Re: Questions regarding specialized malloc()/free() replacements
- From: blargg
- Re: Questions regarding specialized malloc()/free() replacements
- From: Stephan Beal
- Questions regarding specialized malloc()/free() replacements
- Prev by Date: Re: Incremental memory allocation
- Next by Date: Re: Questions regarding specialized malloc()/free() replacements
- Previous by thread: Re: Questions regarding specialized malloc()/free() replacements
- Next by thread: Re: Questions regarding specialized malloc()/free() replacements
- Index(es):
Relevant Pages
|