Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ft_malloc #2

Open
1 task done
gvannest opened this issue Dec 20, 2019 · 2 comments
Open
1 task done

ft_malloc #2

gvannest opened this issue Dec 20, 2019 · 2 comments

Comments

@gvannest
Copy link
Owner

gvannest commented Dec 20, 2019

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
@gvannest
Copy link
Owner Author

gvannest commented Dec 21, 2019

to do next on ft_malloc branch:

  • check with lldb if the g_mallocptr.tinychk points towards a free block with a header and a size of 132kb.
    check this : https://stackoverflow.com/questions/3875055/how-to-use-gdb-to-explore-the-stack-heap

    see command in comments. Yes there is a free block with a free header at the beg of the heap, but could not find the command to get the size of the heap and the first address of the heap

  • What should we do when requested allocation size is 0? => check true malloc

  • add footer? how --> a new void * pointer

  • split the newly created free block with one allocated chunk of the requested size (512 bytes in current exemple cf main), and one new free block of the remaining free size

  • complete the ft_tiny function with the case where there is no need for a new heap (new free chunk allocation)

  • treat the case where there is a new heap allocation: set the pointer to the new (free chunk list!) of the new heap in the footer of the last one (kind of new g_mallocptr.tinychk)

  • do it for small

  • do the work for large : slightly different because direct mmap allocation, no heap .

  • show_alloc_mem function (mandatory) .

  • mettre le begin_free_list a NULL si aucunu free block (a checker au moment de l'alloc) .

  • Go back on branch temp-header-footer-heap: We cannot assume not munmap because we munmap large chunks. Hence we need to set the footer with END_ZONE_FLAG and pointer to next zone + HEADER with pointer to previous footer

  • opti tiny/ small/ large chunks? What does the correction say?

  • mutex lock in show alloc mem

@gvannest
Copy link
Owner Author

gvannest commented Dec 24, 2019

lldb command to print memory

WATCH OUT: we are in little endian (bytes are organized from left to right)

>lldb ./ft_malloc_exec


>b main_test:19 => set a breakpoint at line 19 in main_test.c


>r => run the program


{ breakpoint is reach }
>memory read 0x1000df000 --count 32 => the address has been printed above during the
execution of the program. 32 for 32 bytes

@capaquet capaquet reopened this Dec 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants