Giter Club home page Giter Club logo

ft_malloc's People

Contributors

gvannest avatar

Watchers

 avatar

ft_malloc's Issues

Bonuses

bonuses

  • ft_calloc
  • making malloc thread safe
  • defrag
  • print memory
  • les 2 fonctions du collegue d' Aziz

malloc project global conception

Main documents

https://sourceware.org/glibc/wiki/MallocInternals#Overview_of_Malloc

https://sploitfun.wordpress.com/2015/02/10/understanding-glibc-malloc/

https://www.blackhat.com/presentations/bh-usa-07/Ferguson/Whitepaper/bh-usa-07-ferguson-WP.pdf

https://wiki-prog.infoprepa.epita.fr/images/0/04/Malloc_tutorial.pdf

Decisions

  • One global variable : pointer to first free chunk in the free list.

  • Two header types: one for free and one for allocated chunks (cf doc above)

  • One call mmap = one heap (for ex 132Kb for tiny) corresponding to one allocaiton type (tiny or small). Once the heap is full -> call mmap again and link the two heaps with a pointer at the end of the first heap

  • Large allocations => direct call to mmap (no heap) and direct call to unmmap when free is called on them

  • when a chunk is free'd : check flag (P) to see if previous chunk is free, and combine them in the free list in case it is. However change header in heap block

  • WATCH OUT: the free list is only pointers to free chunks. indeed all the info (pointers to next and previous bloc + size) are in the header which has been changed when the program calls free on an allocated chunk. IT IS NOT A NEW DATA STRUCTURE! We only have the first pointer of the free list in a global variable, and then in the headers of the free chunks we have the necessary data to jump to the next free chunk + size

  • WATCH OUT: ALIGNMENT. chunks must be multiples of 8 bytes. So minimum allocated chunk is 16 bytes : 2 times 4 bytes for the 2 size_t variables in the header, + minimum 8 bytes for user data.

  • for defragmentation: when triggger (len of free list > threshold?) => defrag

  • Errors management: check what fbabin has done on ftp. Using an enum with error codes?

To be decided

  • Do we need a footer on the heap to know where the end of the allocated heap lies?
  • when do we call unmmap on allocated heaps? WATH OUT: when unmmap is called do not forget to clean free list with free chunks in the unmmap'd region! SHould we wait for two heaps to be empty berfore unmmapping the last one?
  • threshold for defragmentation
  • no decision on realloc. to be taken

Main sub topics

mandatory part

  • ft_malloc
  • ft_free
  • ft_realloc

Child issues

ft_free

To check

  • what is the behavior of the real free when the address does not exist?
  • munmap les heaps vides
  • checker les doubles free

ft_malloc

Main issue for the ft_malloc function which deals with the allocation of memory

Note: free is in another issue, please refer to #1

Tasks

  • Create a heap: call mmap, add header, unmmap

specific documentation for implementation

If n is zero, malloc returns a minumum-sized chunk. (The minimum
--
size is 16 bytes on most 32bit systems, and 24 or 32 bytes on 64bit
systems.)  On most systems, size_t is an unsigned type, so calls
with negative arguments are interpreted as requests for huge amounts
of space, which will often fail. The maximum supported value of n
differs across systems, but is in all cases less than the maximum
representable value of a size_t.

Main decisions on implementation

  • @capaquet I suggest for simplicity that we keep the previous size in the header of every chunk, and not only those where the previous chunk is free. The goal of the true implementation is not to loose expensive memory, but I think it over complicates the job her

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.