Sujet : Re: Which code style do you prefer the most?
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.lang.cDate : 25. Feb 2025, 23:48:40
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vplhc7$26ur1$3@dont-email.me>
References : 1
User-Agent : Pan/0.162 (Pokrosvk)
On Tue, 25 Feb 2025 21:15:12 +0600, Ar Rakin wrote:
Which one of the following do you prefer the most?
None of them:
struct malloc_chunk /* header on each memory block */
{
struct malloc_chunk *next; /* doubly-linked list */
struct malloc_chunk *prev;
bool is_free;
size_t size;
} /*malloc_chunk*/;
static inline void * get_chunk_ptr
(
struct malloc_chunk * chunk
)
/* returns pointer to the memory block excluding the header. */
{
return
(void *)(chunk + 1);
} /*get_chunk_ptr*/
void * malloc
(
size_t size
)
/* allocates a memory block of the specified size,
or NULL if none available. */
{
struct malloc_chunk * chunk = mm_find_chunk
(
/*size = */ size,
/*type =*/ MM_CHUNK_FREE
);
if (chunk == NULL)
{
chunk = mm_alloc_chunk(size);
} /*if*/
return
chunk != NULL ?
get_chunk_ptr(chunk)
:
NULL;
} /*malloc*/