Hi Dave,
Great, thanks for the quick reply.
Thanks for clarifying the same, I tried out a quick example and it seems
okay.

Harish
On Wed, Dec 5, 2018 at 1:52 PM Dave Barach (dbarach) <dbar...@cisco.com>
wrote:

> You can have as many heaps as you need. There is no inherent limit. The
> constant CLIB_MAX_MHEAPS has to do with the number of distinct thread-id’s
> which os_get_thread_index() will return.
>
>
>
> This guitar-lick means “temporarily use the supplied heap for all
> allocations”:
>
>
>
>   void *oldheap = clib_mem_set_heap (heap);
>
>       pool_get() / vec_validate() / clib_mem_alloc() etc. as desired
>
>   clib_mem_set_heap(oldheap); // back to the previous heap, usually the
> shared global heap...
>
>
>
> Required when allocating / free memory in the binary API segment, and in
> private heaps.
>
>
>
> Note that clib_mem_alloc() and variants mean “allocate memory from the
> current per-thread heap,” which is easily changed for a moment as shown
> above.
>
>
>
> Please read through src/vppinfra/{mem.h, dlmalloc.[ch]} carefully and
> understand what’s going on before you jump in.
>
>
>
> D.
>
>
>
> *From:* vpp-dev@lists.fd.io <vpp-dev@lists.fd.io> *On Behalf Of *Harish
> Patil
> *Sent:* Wednesday, December 5, 2018 4:31 PM
> *To:* vpp-dev@lists.fd.io
> *Subject:* [vpp-dev] Heap allocation
>
>
>
> Hi,
>
>
>
> I would like to pre-allocate separate heap space (outside of main heap)
> and be able to use the returned memory for my application's memory needs
> (just like malloc()). It seems we can have up to 256 heaps. Have few
> questions around this:
>
>
>
> 1) My understanding is that currently the main heap is allocated using
> clib_mem_init()/clib_mem_init_thread_safe() and the subsequent calls like
> clib_mem_alloc(size) will carve out memory from within the main heap and
> returned to clients (similar to glibc malloc()). Is this correct? If so, I
> would like to know how this is achieved since I don't see the returned
> pointer from clib_mem_init()/clib_mem_init_thread_safe() is being
> referenced or used anywhere.
>
>
>
> 2) Some applications are using mheap_alloc() directly to create new heap.
>
> Ex:
>
> void *heap;
>
> void *oldheap;
>
> heap = mheap_alloc (0, 10<<20);
>
> oldheap = clib_mem_set_heap (heap);
>
> ..
>
> ..
>
> clib_mem_set_heap (oldheap); << why is this required to write back oldheap
> into per-cpu heap?
>
>
>
> What I really like to know is once the heap is allocated how can we use
> it? Does it imply to have pools/hashes to be created to be able to use it?
> I'm expecting something which takes void *heap (created using mheap_alloc)
> and returns the requested memory for a given size from within the heap so
> that we don't need to use pools/hashes.
>
> Ex: void *foobar(void *mheap, size_t size);
>
> Is it possible?
>
> Thanks,
>
>
>
> Harish
>
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#11505): https://lists.fd.io/g/vpp-dev/message/11505
Mute This Topic: https://lists.fd.io/mt/28617718/21656
Group Owner: vpp-dev+ow...@lists.fd.io
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to