|
libft
|
Functions for low-level memory operations. More...
Files | |
| file | ft_memory.c |
| Low-level memory manipulation utilities. | |
| file | ft_memory.h |
| Low-level memory manipulation functions. | |
Functions | |
| void | ft_bzero (void *s, size_t n) |
| Sets a block of memory to zero. | |
| void * | ft_calloc (size_t nmemb, size_t size) |
| Allocates and zeroes memory for an array. | |
| void * | ft_memchr (const void *s, int c, size_t n) |
| Scans memory for a specific byte. | |
| int | ft_memcmp (const void *s1, const void *s2, size_t n) |
| Compares two memory blocks. | |
| void * | ft_memcpy (void *dest, const void *src, size_t n) |
| Copies memory from source to destination. | |
| void * | ft_memmove (void *dest, const void *src, size_t n) |
| Copies memory safely, handling overlapping regions. | |
| void * | ft_memset (void *s, int c, size_t n) |
| Fills memory with a constant byte. | |
| void * | ft_realloc (void *ptr, size_t old_size, size_t new_size) |
| Resizes a memory block. | |
Functions for low-level memory operations.
This group contains functions that replicate or extend common C standard library memory operations, including:
ft_calloc, ft_realloc)ft_bzero, ft_memset)ft_memcpy, ft_memmove)ft_memcmp, ft_memchr)These utilities provide safer or more convenient alternatives to their standard counterparts and are useful throughout custom C projects.
This group includes:
| void ft_bzero | ( | void * | s, |
| size_t | n | ||
| ) |
#include <include/ft_memory.h>
Sets a block of memory to zero.
Sets the first n bytes of the memory area pointed to by s to zero ('\0' bytes). Useful for initializing buffers or memory blocks.
| s | Pointer to the memory area to zero out. |
| n | Number of bytes to set to zero. |
bzero function. Often used with malloc, calloc, or custom memory allocators.| void * ft_calloc | ( | size_t | nmemb, |
| size_t | size | ||
| ) |
#include <include/ft_memory.h>
Allocates and zeroes memory for an array.
Allocates memory for nmemb elements of size bytes each and initializes all memory to zero. Includes overflow protection.
| nmemb | Number of elements. |
| size | Size of each element in bytes. |
malloc(nmemb * size) followed by ft_memset(ptr, 0,
...).| void * ft_memchr | ( | const void * | s, |
| int | c, | ||
| size_t | n | ||
| ) |
#include <include/ft_memory.h>
Scans memory for a specific byte.
Searches the first n bytes of the memory area pointed to by s for the first occurrence of the byte c.
| s | Pointer to the memory block to scan. |
| c | Byte to search for. |
| n | Number of bytes to scan. |
| int ft_memcmp | ( | const void * | s1, |
| const void * | s2, | ||
| size_t | n | ||
| ) |
#include <include/ft_memory.h>
Compares two memory blocks.
Compares the first n bytes of memory areas s1 and s2. Comparison is done byte by byte using unsigned characters.
| s1 | Pointer to the first memory block. |
| s2 | Pointer to the second memory block. |
| n | Number of bytes to compare. |
| void * ft_memcpy | ( | void * | dest, |
| const void * | src, | ||
| size_t | n | ||
| ) |
#include <include/ft_memory.h>
Copies memory from source to destination.
Copies n bytes from src to dest. Performs fast 8-byte chunks when possible. Does not support overlapping memory regions.
| dest | Pointer to destination memory. |
| src | Pointer to source memory. |
| n | Number of bytes to copy. |
dest, or NULL if either pointer is NULL.ft_memmove instead when memory regions overlap. | void * ft_memmove | ( | void * | dest, |
| const void * | src, | ||
| size_t | n | ||
| ) |
#include <include/ft_memory.h>
Copies memory safely, handling overlapping regions.
Copies n bytes from src to dest. Chooses forward or backward copy direction based on pointer alignment to avoid corruption.
| dest | Pointer to destination memory. |
| src | Pointer to source memory. |
| n | Number of bytes to copy. |
dest.| void * ft_memset | ( | void * | s, |
| int | c, | ||
| size_t | n | ||
| ) |
#include <include/ft_memory.h>
Fills memory with a constant byte.
Sets the first n bytes of the memory area pointed to by s to the byte value c, converted to unsigned char.
| s | Pointer to the memory area to fill. |
| c | Byte value to write into memory. |
| n | Number of bytes to write. |
s. | void * ft_realloc | ( | void * | ptr, |
| size_t | old_size, | ||
| size_t | new_size | ||
| ) |
#include <include/ft_memory.h>
Resizes a memory block.
Allocates new memory of size new_size, copies up to old_size bytes from ptr into the new block, and frees the old memory.
| ptr | Pointer to previously allocated memory. |
| old_size | Size of the old block. |
| new_size | Desired new size. |
ptr is NULL, behaves like malloc(new_size). If new_size is 0, frees memory and returns NULL.