Coder Social home page Coder Social logo

42_garbage_memory's Introduction

Tracker à la norme

Un tracker, pourquoi?

Le tracker permet de référencer les pointeurs alloué dynamiqument dans un annuaire. De cette façon adieu les leaks 😉.

Compilation

  • Compilation de la librairie
make
  • Compilation
LIB_TRACKER	:=	-Ltracker -ltracker
$(CC) $(CFLAGS) $(LIB_TRACKER) ## and your main / objects  ... ##

Usage

#include "tracker/includes/tracker.h"

int	main(void)
{
	t_track	*track;

	track = ft_new_tracker();
	if (!track)
		return (1);

	// Do anything you want (just add all allocation [malloc...] to the tracker)


	ft_track_free_all(&track);
	return (0);
}

Le define DEBUG_TRACK dans le tracker.h permet de montrer d'éventuel erreurs lors de l'utilisation du tracker.

L'utilisation du tracker sur plusieurs dimensions ajoute les pointeurs de toutes les dimensions

Donc dans le cas d'un split par exemple, s'il on veut free une ligne, il faudra la free avec le tracker avec ft_track_free ou ft_track_dim_free ou ne pas le free du tout et laisser ft_track_free_all de fin tout régler (pas propre mais fonctionnel).

Avertissement

Par defaut, la fonction ft_track_dim retourne NULL si l'allocation du tracker échou ou si le pointeur passé est NULL. Dans le cas, d'une erreur d'allocation du tracker, le pointeur est également free.

Si l'on veut qu'en cas d'erreur d'allocation du tracker, le pointeur ne soit pas free. Il faut changer le define FREE_IF_ERROR à 0.

Prototypes

Track

// create a tracker
t_track	*ft_new_tracker(void);
// Add a pointer at n dimension to the tracker
void	*ft_track_dim(t_track **track, void **ptr, size_t level);
// Add a simple pointer to the tracker
void	*ft_track(t_track **track, void *ptr);

Free

// Remove the pointer and them dimensions from the tracker and free the pointer
// and all the dimensions
void	ft_track_dim_free(t_track **track, void **ptr, size_t level);
// Remove the pointer from the tracker and free the pointer
void	ft_track_free(t_track **track, void *ptr);
// Free all the pointers track by the tracker and free the tracker
void	ft_track_free_all(t_track **track);

42_garbage_memory's People

Contributors

valktaelen avatar

Stargazers

jmilhas avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.