42sh 1.0.0
Create a shell in C
Loading...
Searching...
No Matches
mymemory.h File Reference

The header file of the libmymemory. More...

#include "mylist.h"

Go to the source code of this file.

Macros

#define MYMEMORY_H_
 
#define CALLOC(elt_count, elt_size)   my_calloc(elt_count, elt_size, 1)
 
#define MALLOC(size)   my_malloc(size, 1)
 
#define REALLOC(ptr, size)   my_realloc(ptr, size, 1)
 

Functions

void * my_calloc (size_t element_count, size_t element_size, int type)
 Allocates memory for an array of elements (element_count) of bytes (element_size) each and initializes the memory to zero.
 
void my_free (void)
 Free allocated memory with my_calloc, my_malloc and my_realloc.
 
void * my_malloc (size_t size, int type)
 Allocates memory for an array of bytes (size)
 
char * my_malloc_strdup (char const *src)
 Duplicates a string with my_malloc.
 
char ** my_malloc_strdup_word_array (char **array)
 Duplicates a word array (array) with my_malloc.
 
char * my_malloc_strndup (char const *src, int n)
 Duplicates a string with a defined size with my_malloc.
 
void * my_memchr (const void *memory_block, int searched_char, size_t size)
 Copies bytes (size) from memory area (source) to memory area (destination)
 
void * my_memcpy (void *destination, const void *source, size_t size)
 Copies bytes (size) from memory area (source) to memory area (destination)
 
int my_memcmp (const void *pointer1, const void *pointer2, size_t size)
 Compares the first (size) bytes of the two memory areas (pointer1 and pointer2)
 
void * my_memmove (void *destination, const void *source, size_t size)
 Moves bytes (size) from memory area (source) to memory area (destination)
 
void * my_memset (void *pointer, int value, size_t size)
 Fill bytes (size) of memory area (pointer) with a value (value)
 
void * my_realloc (void *pointer, size_t size, int type)
 Reallocates memory for an array of bytes (size)
 

Detailed Description

The header file of the libmymemory.

Author
Nicolas TORO

Function Documentation

◆ my_calloc()

void * my_calloc ( size_t element_count,
size_t element_size,
int type )

Allocates memory for an array of elements (element_count) of bytes (element_size) each and initializes the memory to zero.

Note
type = 0: Free allocated memory with my_calloc
type = 1: Allocate memory
Parameters
element_countThe number of elements
element_sizeThe size of each element
typeThe type of the usage
Returns
void * A pointer to the allocated memory
Author
Nicolas TORO

◆ my_free()

void my_free ( void )

Free allocated memory with my_calloc, my_malloc and my_realloc.

Returns
void
Author
Nicolas TORO

◆ my_malloc()

void * my_malloc ( size_t size,
int type )

Allocates memory for an array of bytes (size)

Note
type = 0: Free allocated memory with my_malloc
type = 1: Allocate memory
Parameters
sizeThe size of the memory to allocate
typeThe type of the usage
Returns
void * A pointer to the allocated memory
Author
Nicolas TORO

◆ my_malloc_strdup()

char * my_malloc_strdup ( char const * src)

Duplicates a string with my_malloc.

Note
The duplicated string must be free only with my_free
Parameters
srcThe string to duplicate
Returns
char * A pointer to the duplicated string
Author
Nicolas TORO

◆ my_malloc_strdup_word_array()

char ** my_malloc_strdup_word_array ( char ** array)

Duplicates a word array (array) with my_malloc.

Note
The duplicated word array must be free only with my_free
Parameters
arrayThe word array to duplicate
Returns
char ** A pointer to the duplicated word array
Author
Nicolas TORO

◆ my_malloc_strndup()

char * my_malloc_strndup ( char const * src,
int n )

Duplicates a string with a defined size with my_malloc.

Note
The duplicated string must be free only with my_free
Parameters
srcThe string to duplicate
nThe size of the string
Returns
char* A pointer to the duplicated string
Author
Nicolas TORO

◆ my_memchr()

void * my_memchr ( const void * memory_block,
int searched_char,
size_t size )

Copies bytes (size) from memory area (source) to memory area (destination)

Parameters
destinationThe destination memory area
sourceThe source memory area
sizeThe number of bytes to copy
Returns
void * A pointer to the destination memory area
Author
Nicolas TORO

◆ my_memcmp()

int my_memcmp ( const void * pointer1,
const void * pointer2,
size_t size )

Compares the first (size) bytes of the two memory areas (pointer1 and pointer2)

Parameters
pointer1The first memory area
pointer2The second memory area
sizeThe number of bytes to compare
Returns
int 0 if the strings are identical, otherwise the difference between the first different byte in the memory areas
Author
Nicolas TORO

◆ my_memcpy()

void * my_memcpy ( void * destination,
const void * source,
size_t size )

Copies bytes (size) from memory area (source) to memory area (destination)

Parameters
destinationThe destination memory area
sourceThe source memory area
sizeThe number of bytes to copy
Returns
void * A pointer to the destination memory area
Author
Nicolas TORO

◆ my_memmove()

void * my_memmove ( void * destination,
const void * source,
size_t size )

Moves bytes (size) from memory area (source) to memory area (destination)

Note
Did the same as my_memcpy
Parameters
destinationThe destination memory area
sourceThe source memory area
sizeThe number of bytes to copy
Returns
void * A pointer to the destination memory area
Author
Nicolas TORO

◆ my_memset()

void * my_memset ( void * pointer,
int value,
size_t size )

Fill bytes (size) of memory area (pointer) with a value (value)

Parameters
pointerThe memory area to fill
valueThe value to fill the memory area with
sizeThe number of bytes to fill
Returns
void * A pointer to the memory area filled with (value)
Author
Nicolas TORO

◆ my_realloc()

void * my_realloc ( void * pointer,
size_t size,
int type )

Reallocates memory for an array of bytes (size)

Note
type = 0: Free allocated memory with my_realloc
type = 1: Allocate memory
Parameters
pointerThe pointer to the memory to reallocate
sizeThe size of the memory to reallocate
typeThe type of the usage
Returns
void * A pointer to the reallocated memory
Author
Nicolas TORO