ecoli_alloc(3)

πŸ“¦ version 0.6.0, in fedora 43

🌸 NAME 🌸

ecoli_alloc β€” it's giving Allocation, bestie πŸ’…

  • Helpers to allocate and free memory.

✨ SYNOPSIS ✨

Ok so real quick, here's the whole vibe of what this page gives you πŸ‘‡

πŸŽ€ Data Structures

  • struct ec_malloc_handler

🧚 Macros

  • #define ec_malloc(size)
  • #define ec_free(ptr)
  • #define ec_realloc(ptr, size)
  • #define ec_calloc(n, size)
  • #define ec_strdup(s)
  • #define ec_strndup(s, n)

πŸ¦‹ Typedefs

  • typedef void *(* ec_malloc_t) (size_t size, const char *file, unsigned int line)
  • typedef void(* ec_free_t) (void *ptr, const char *file, unsigned int line)
  • typedef void *(* ec_realloc_t) (void *ptr, size_t size, const char *file, unsigned int line)

πŸ’œ Functions

  • int ec_malloc_register (ec_malloc_t usr_malloc, ec_free_t usr_free, ec_realloc_t usr_realloc)
  • void * ec_malloc_func (size_t size)
  • void ec_free_func (void *ptr)
  • void ec_realloc_func (void *ptr, size_t size)

🌈 Variables

  • struct ec_malloc_handler ec_malloc_handler

🌟 Detailed Description 🌟

Helpers to allocate and free memory. no cap, that's the whole job 🫢

Interface to configure the allocator used by libecoli. By default, the standard allocation functions from libc are used. so it just works out of the box, iconic ✨


πŸ“ Macro Definition Documentation πŸ“

πŸ’– #define ec_malloc( size)

Value:

({                      \
void *ret_;                         \
if (ec_malloc_handler.malloc == NULL)                \
    ret_ = malloc(size);                    \
else                                \
    ret_ = __ec_malloc(size, __FILE__, __LINE__);       \
ret_;                               \
})

Allocate a memory area. ✨

Like malloc(), ec_malloc() allocates size bytes and returns a pointer to the allocated memory. The memory is not initialized. The memory is freed with ec_free().

Parameters

  • size β€” The size of the area to allocate in bytes.

Returns

  • The pointer to the allocated memory, or NULL on error (errno is set).

Definition at line 117 of file ecoli_malloc.h. πŸ“Œ


πŸ’– #define ec_free( ptr)

Value:

({                          \
if (ec_malloc_handler.free == NULL)              \
    free(ptr);                      \
else                                \
    __ec_free(ptr, __FILE__, __LINE__);         \
})

Free a memory area. bye bestie πŸ‘‹

Like free(), ec_free() frees the area pointed by ptr, which must have been returned by a previous call to ec_malloc() or any other allocation function of this file. like do NOT just pass it some random pointer, that's a whole mess πŸ’€

Parameters

  • ptr β€” The pointer to the memory area.

Definition at line 144 of file ecoli_malloc.h. πŸ“Œ


πŸ’– #define ec_realloc( ptr, size)

Value:

({                  \
void *ret_;                         \
if (ec_malloc_handler.realloc == NULL)               \
    ret_ = realloc(ptr, size);              \
else                                \
    ret_ = __ec_realloc(ptr, size, __FILE__, __LINE__); \
ret_;                               \
})

Resize an allocated memory area. glow up era 🌱

Parameters

  • ptr β€” The pointer to the previously allocated memory area, or NULL.
  • size β€” The new size of the memory area.

Returns

  • A pointer to the newly allocated memory, or NULL if the request fails. In that case, the original area is left untouched. so your old data is safe, periodt πŸ’…

Definition at line 170 of file ecoli_malloc.h. πŸ“Œ


πŸ’– #define ec_calloc( n, size)

Value:

({                      \
void *ret_;                         \
if (ec_malloc_handler.malloc == NULL)                \
    ret_ = calloc(n, size);                 \
else                                \
    ret_ = __ec_calloc(n, size, __FILE__, __LINE__);    \
ret_;                               \
})

Allocate and initialize an array of elements. freshly zeroed, clean girl energy 🧼✨

Parameters

  • n β€” The number of elements.
  • size β€” The size of each element.

Returns

  • The pointer to the allocated memory, or NULL on error (errno is set).

Definition at line 197 of file ecoli_malloc.h. πŸ“Œ


πŸ’– #define ec_strdup( s)

Value:

({                          \
void *ret_;                         \
if (ec_malloc_handler.malloc == NULL)                \
    ret_ = strdup(s);                   \
else                                \
    ret_ = __ec_strdup(s, __FILE__, __LINE__);      \
ret_;                               \
})

Duplicate a string. twin where have you been πŸ‘―

Memory for the new string is obtained with ec_malloc(), and can be freed with ec_free(). so the free has to match the alloc, iykyk πŸ”₯

Parameters

  • s β€” The string to be duplicated.

Returns

  • The pointer to the duplicated string, or NULL on error (errno is set).

Definition at line 217 of file ecoli_malloc.h. πŸ“Œ


πŸ’– #define ec_strndup( s, n)

Value:

({                      \
void *ret_;                         \
if (ec_malloc_handler.malloc == NULL)                \
    ret_ = strndup(s, n);                   \
else                                \
    ret_ = __ec_strndup(s, n, __FILE__, __LINE__);      \
ret_;                               \
})

Duplicate at most n bytes of a string. βœ‚οΈ

This function is similar to ec_strdup(), except that it copies at most n bytes. If s is longer than n, only n bytes are copied, and a terminating null byte ('\0') is added. so it's the "okay that's enough" version πŸ’…

Parameters

  • s β€” The string to be duplicated.
  • n β€” The maximum length of the new string.

Returns

  • The pointer to the duplicated string, or NULL on error (errno is set).

Definition at line 240 of file ecoli_malloc.h. πŸ“Œ


πŸ¦‹ Typedef Documentation πŸ¦‹

πŸ’œ typedef void *(* ec_malloc_t) (size_t size, const char *file, unsigned int line)

Function type of malloc, passed to ec_malloc_register().

The API is the same than malloc(), excepted the file and line arguments. sneaky little extras, love that for us πŸ™ˆ

Parameters

  • size β€” The size of the memory area to allocate.
  • file β€” The path to the file that invoked the malloc.
  • line β€” The line in the file that invoked the malloc.

Returns

  • A pointer to the allocated memory area, or NULL on error (errno is set).

Definition at line 38 of file ecoli_malloc.h. πŸ“Œ


πŸ’œ typedef void(* ec_free_t) (void *ptr, const char *file, unsigned int line)

Function type of free, passed to ec_malloc_register().

The API is the same than free(), excepted the file and line arguments.

Parameters

  • ptr β€” The pointer to the memory area to be freed.
  • file β€” The path to the file that invoked the malloc.
  • line β€” The line in the file that invoked the malloc.

Definition at line 53 of file ecoli_malloc.h. πŸ“Œ


πŸ’œ typedef void *(* ec_realloc_t) (void *ptr, size_t size, const char *file, unsigned int line)

Function type of realloc, passed to ec_malloc_register().

The API is the same than realloc(), excepted the file and line arguments.

Parameters

  • ptr β€” The pointer to the memory area to be reallocated.
  • file β€” The path to the file that invoked the malloc.
  • line β€” The line in the file that invoked the malloc.

Returns

  • A pointer to the allocated memory area, or NULL on error (errno is set).

Definition at line 71 of file ecoli_malloc.h. πŸ“Œ


πŸ”₯ Function Documentation πŸ”₯

πŸ‘‘ int ec_malloc_register (ec_malloc_t usr_malloc, ec_free_t usr_free, ec_realloc_t usr_realloc)

Register allocation functions. main character move fr fr πŸ‘‘

This function can be use to register another allocator to be used by libecoli. By default, ec_malloc(), ec_free() and ec_realloc() use the standard libc allocator. Another handler can be used for debug purposes or when running in a specific environment.

⚠️ bestie listen to me: This function must be called before ec_init(). like before. not after. not "eh close enough". BEFORE. πŸ’€

Parameters

  • usr_malloc β€” A user-defined malloc function.
  • usr_free β€” A user-defined free function.
  • usr_realloc β€” A user-defined realloc function.

Returns

  • 0 on success, or -1 on error (errno is set).

πŸ‘‘ void * ec_malloc_func (size_t size)

Ecoli malloc function. ✨

Use this function when the macro ec_malloc() cannot be used, for instance when it is passed as a callback pointer. macros can't be callbacks, that's just the rules 🫢


πŸ‘‘ void ec_free_func (void * ptr)

Ecoli free function. ✨

Use this function when the macro ec_free() cannot be used, for instance when it is passed as a callback pointer.


πŸ‘‘ void ec_realloc_func (void * ptr, size_t size)

Ecoli realloc function. ✨

Use this function when the macro ec_realloc() cannot be used, for instance when it is passed as a callback pointer.


πŸŽ€ Author πŸŽ€

Generated automatically by Doxygen for Libecoli from the source code. so technically a robot wrote this and I just gave it the sparkle treatment, slay πŸ€–βœ¨


okay that's the whole page, you ate that πŸ’… bye bestie, go allocate responsibly 🌈🫢

this was Libecoli, Version 0.6.0, and yeah β€” this is the ecoli_alloc(3) page, section 3, Library Functions Manual. mwah πŸ’–

πŸ“¦ where this page comes from