Adding malloc implementation #16
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reason for the Pull Request
See issue #15,
mallocandfreeare declared in the stdlib header of the pulp-runtime but are not actually implemented as of commit 252cecb.Changes introduced by the Pull Request
This pull request introduces 3 main changes in the codebase:
In alloc_pool.h, two functions were added:
pos_alloc_user_dataandpos_free_user_data. These functions are used to hide from the user the location where the data is allocated, which may change with the hardware (as was the case in pulp-rt, see rt_alloc). That way, thepos_alloc_tstructs are only visible within alloc_pool.c and not exposed to the end user.In alloc_pool.c, I added the implementations for
pos_alloc_user_dataandpos_free_user_data. The preferred locations to put the data are the same as in rt_alloc.In io.c, I added the implementation for
mallocandfree. The implementation is similar to that used in the io.c of pulp-rt in that the size of the allocated chunk is stored before the pointer given to the user.Additional Notes
I tried to keep the same style as the rest of the codebase so that the code would blend in well, and I also reused names from pulp-rt.
I haven't thoroughly tested the code yet, but I should be able to during the week. I can post a small update then if the PR hasn't been merged yet.
Finally, the internal
pos_allocin alloc.c usesintfor the size, whilemallocstores it as auint32_t. I kept that from the original codebase to avoid introducing many changes at once, but it might cause bugs in edge cases where a size >2GB is allocated at once.