80x24.org misc. Free Software, open data formats/protocols discussion
 help / color / mirror / Atom feed
* dlmalloc has mspace support
@ 2014-07-21  2:35 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2014-07-21  2:35 UTC (permalink / raw)
  To: misc

Apparently newish versions of the venerable dlmalloc has an mspace API.

This could prove promising for some servers which dynamically
spawn/destroy independent applications and would benefit from different

Quoted from ftp://gee.cs.oswego.edu/pub/misc/malloc.c
  If MSPACES is defined, then in addition to malloc, free, etc.,
  this file also defines mspace_malloc, mspace_free, etc. These
  are versions of malloc routines that take an "mspace" argument
  obtained using create_mspace, to control all internal bookkeeping.
  If ONLY_MSPACES is defined, only these versions are compiled.
  So if you would like to use this allocator for only some allocations,
  and your system malloc for others, you can compile with
  ONLY_MSPACES and then do something like...
    static mspace mymspace = create_mspace(0,0); // for example
    #define mymalloc(bytes)  mspace_malloc(mymspace, bytes)

  (Note: If you only need one instance of an mspace, you can instead
  use "USE_DL_PREFIX" to relabel the global malloc.)

  You can similarly create thread-local allocators by storing
  mspaces as thread-locals. For example:
    static __thread mspace tlms = 0;
    void*  tlmalloc(size_t bytes) {
      if (tlms == 0) tlms = create_mspace(0, 0);
      return mspace_malloc(tlms, bytes);
    void  tlfree(void* mem) { mspace_free(tlms, mem); }

  Unless FOOTERS is defined, each mspace is completely independent.
  You cannot allocate from one and free to another (although
  conformance is only weakly checked, so usage errors are not always
  caught). If FOOTERS is defined, then each chunk carries around a tag
  indicating its originating mspace, and frees are directed to their
  originating spaces. Normally, this requires use of locks.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-07-21  2:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-21  2:35 dlmalloc has mspace support Eric Wong

80x24.org misc. Free Software, open data formats/protocols discussion

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://80x24.org/misc
	git clone --mirror http://ou63pmih66umazou.onion/misc

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 misc misc/ https://80x24.org/misc \
	public-inbox-index misc

Example config snippet for mirrors.
Newsgroups are available over NNTP:
 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inbox.git