项目作者: ulefebvr

项目描述 :
Dynamic memory allocator library.
高级语言: C
项目地址: git://github.com/ulefebvr/ft_memalloc.git
创建时间: 2017-01-16T17:49:29Z
项目社区:https://github.com/ulefebvr/ft_memalloc

开源协议:

下载


ft_memalloc

42born2code school project consisting in creating a thread-safe dynamic memory allocator library.


Compile the library

Use make command to compile the library. To overload the system memory-allocator you have to set these environment variables.

  1. if [ "$(uname)" == "Linux" ]; then
  2. export LD_LIBRARY_PATH=$(dirname $(readlink -f path_to_depo/libft_malloc.so))/
  3. export LD_PRELOAD=$(readlink -f path_to_depo/libft_malloc.so)
  4. else
  5. export DYLD_LIBRARY_PATH=path_to_depo/
  6. export DYLD_INSERT_LIBRARIES="path_to_depo/libft_malloc.so"
  7. export DYLD_FORCE_FLAT_NAMESPACE=1
  8. fi

Library description

  • This memory allocator use the First-Fit method.
  • Size separate treatment. TINY < SMALL < LARGE.
  • Pre-allocation is done for TINY and SMALL allocation.
  • Minimal overhead.

The library includes the following functions:

  1. void free(void *ptr);
  2. void *malloc(size_t size);
  3. void *calloc(size_t count, size_t size);
  4. void *realloc(void *ptr, size_t size);
  5. void *reallocf(void *ptr, size_t size);
  6. void show_alloc_mem(void);

show_alloc_mem show the allocated memory status.


Tests

You can use the test/test.py to test the library.

  1. $> ./test.py
  2. #####Test malloc
  3. Page reclaims for test0 (NO MALLOC, initial PR): 252
  4. Page reclaims for test1 (WITH MALLOC, PR Full Load): 520
  5. Page reclaims for test2: 252
  6. For test1 (minus test0 for compensation) the PR is: 268 --> Score (out of 5):
  7. 5/5
  8. entre 255 et 272 pages, le malloc fonctionne et l'overhead est raisonnable
  9. #####Test free
  10. Page reclaims for test0 (NO MALLOC, initial PR): 252
  11. Page reclaims for test2: 252
  12. delta PR between test2 and test0: 0
  13. Max 3 page reclaim more than test0. The free is working as expected !
  14. #####Test realloc
  15. OK
  16. #####Test realloc++
  17. OK
  18. #####Test Thread-Safe
  19. OK
  20. #####Test errors
  21. OK
  22. #####Test print_alloc_mem
  23. SMALL
  24. 10C6B4000 - 10C6B4400 : 1024 octets
  25. LARGE
  26. 10D7D8028 - 1157D8028 : 134217728 octets
  27. 10C7D7028 - 10D7D7028 : 16777216 octets
  28. 10C6D6028 - 10C7D6028 : 1048576 octets
  29. 10C6CD028 - 10C6D5028 : 32768 octets
  30. #####Test `ls` command
  31. OK
  32. #####Test `ls -l` command
  33. OK
  34. #####Test `ls -lR ..` command
  35. OK
  36. #####Test `ls -Rla ~` command
  37. OK
  38. #####Test `grep malloc *` command
  39. OK