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

Implement linearRealloc #541

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

BallM4788
Copy link

@BallM4788 BallM4788 commented Mar 19, 2024

linearAlloc() was declared but never implemented. @WinterMute anything I'm missing or needs to be fixed?

Nitty gritty:


Reallocates a buffer by shrinking or growing the size listed in the associated MemChunk, and appropriately growing or shrinking the size listed in the MemBlock associated with the adjacent unallocated memory.

  • linearRealloc() will adjust the requested size to comply with the buffer's linear mask. A new member linearMask has been added to the memChunk struct to facilitate this. If the adjusted size is identical to the MemChunk's existing size, no modification is done.
  • If shrinking the buffer results in a section of unallocated memory where none existed prior, a new MemBlock will be appropriately inserted into the linear pool.
  • When growing the buffer, the initially-mentioned MemBlock will be deleted if its resulting size is 0. If the adjacent unallocated memory section is insufficient for expanding the buffer, linearRealloc() will:
    1. Attempt to allocate a new buffer of the desired size. Continue with the following steps if successful.
    2. Copy the contents of the original buffer into the new buffer.
    3. Deallocate the original buffer.

In successful cases, LinearAlloc() will return a pointer to the reallocated memory. If reallocation fails at any point, no changes are made and a null pointer is returned.

@BallM4788 BallM4788 marked this pull request as draft March 28, 2024 19:15
@BallM4788 BallM4788 marked this pull request as ready for review March 29, 2024 16:16
@BallM4788
Copy link
Author

@WinterMute Would you mind checking this out?

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

Successfully merging this pull request may close these issues.

None yet

1 participant