Skip to content

Allocated block expansion without relocation #123

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

Closed
viccpp opened this issue Aug 8, 2019 · 3 comments
Closed

Allocated block expansion without relocation #123

viccpp opened this issue Aug 8, 2019 · 3 comments

Comments

@viccpp
Copy link

viccpp commented Aug 8, 2019

Hello!

It would be good to have some function like realloc() that tries to expand/shrink allocated memory buffer but doesn't try to relocate the block, just returns unsuccessful status when in place reallocation is impossible.

The idea is explained in detail here (it's a proposal for ISO C++).

As examples of a possible solution:

jemalloc has xmallocx() function with the required behaviour (also it returns the real size of the resulting resized allocation as requested in #2).

Windows HeapReAlloc() function has HEAP_REALLOC_IN_PLACE_ONLY flag.

@daanx
Copy link
Collaborator

daanx commented Aug 10, 2019

Thanks for your feedback. The function mi_expand seems to do what you suggest.

@viccpp
Copy link
Author

viccpp commented Aug 15, 2019

AFAICS this function doesn't try to expand anything, just tries to reuse extra allocated space:

void* mi_expand(void* p, size_t newsize) mi_attr_noexcept {
  if (p == NULL) return NULL;
  size_t size = mi_usable_size(p);
  if (newsize > size) return NULL;
  return p; // it fits
}

Could we have true implementation? Does the library support allocated block expansion at all?

@daanx
Copy link
Collaborator

daanx commented Aug 16, 2019

Ah I see what you mean. However, the current design often does have more space available. But at the same time, the design is based on size segregated areas so it does not support further in-place expanding of blocks (well, perhaps we could support it for huge objects).

@daanx daanx closed this as completed Aug 20, 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