_Expand vs. New vs. GNU

I recently made a new friend. His name is expand , and we had pleasant conversations, and I even met him several times. But when I started asking, no one heard of my “expander”. I became suspicious. I called several completely non-metaphorical friends at microsoft and several friends elsewhere in the business. Nothing. No one has ever used it. I have feasted on various search engines and tree sources. Nothing but a cursory mention here and there. Of course, there is not enough performance and compatibility information for me to introduce _expand into production code or, more appropriate, shared libraries.

Worse, there is no equivalent function that I can find in any of the gnu libraries, so anything I crack with my new friend will by no means be portable. What a shame, because it is truly an exciting and exciting ability to have. Of course, I could dig into realloc and figure out how it works, but the problem is that most of the implementation is heavily changed to * nixes. So I would have to use the version of the code after the version to try to get portable _expand. However, it seems ridiculous that nothing of the kind exists in glib or extended gnu libs.

  • Is there a similar function I should know about hacking linux? Mostly answered
  • Is there a standard hook on which I could build a similar function? Answered
  • Does anyone know what kind of performance _expand offers?
  • How does it interact with objects allocated on LFH?

To clarify my interests, I'm trying to create a separately connected drive that expands, trying to minimize fragmentation when distributing blocks with multiple elements in accordance with traditional deque implementations. By limiting the use cases for adding and removing elements, I hope to optimize the time for removal for the entire structure, as well as insert and index elements. As a result, the “loud crash” _expand allows me to make the structure reasonably think about when and if it can resize in place, and what it means about where it can put data.

+8
c ++ memory-management malloc
source share
1 answer

The fact that C ++ works with new and delete without any realloc equivalent shows how little attention is paid to these things. Not surprisingly, _expand is largely ignored when it is not always available at the OS level. If you want to view your own, there are many use cases for custom versions of malloc, and a quick look in /usr/include/malloc.h on my Linux box clearly shows the hooks for this ...

 /* Called once when malloc is initialized; redefining this variable in the application provides the preferred way to set up the hook pointers. */ extern void (*__malloc_initialize_hook) __MALLOC_PMT ((void)); /* Hooks for debugging and user-defined versions. */ extern void (*__free_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr, __const __malloc_ptr_t)); extern __malloc_ptr_t (*__malloc_hook) __MALLOC_PMT ((size_t __size, __const __malloc_ptr_t)); extern __malloc_ptr_t (*__realloc_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr, size_t __size, __const __malloc_ptr_t)); extern __malloc_ptr_t (*__memalign_hook) __MALLOC_PMT ((size_t __alignment, size_t __size, __const __malloc_ptr_t)); extern void (*__after_morecore_hook) __MALLOC_PMT ((void)); 

It doesn't look like you can grab the existing realloc implementation at that particular point in the solution, although it’s either easy to get an idea of ​​whether it will resize in place, so you might have to redefine everything (or adapt any of the many existing heap implementations )

+3
source share

Source: https://habr.com/ru/post/649855/


All Articles