Liste des Groupes | Revenir à cl c |
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*/
Les messages affichés proviennent d'usenet.