comp.lang.ada
 help / color / mirror / Atom feed
From: ldb <ldb_nospam@hotmail.com>
Subject: Problems with dynamic allocation in tasks
Date: Wed, 25 Jul 2007 09:11:04 -0700
Date: 2007-07-25T09:11:04-07:00	[thread overview]
Message-ID: <1185379864.592973.73220@b79g2000hse.googlegroups.com> (raw)

I have a piece of code that runs great under linux using GNAT and
terrible under Windows also using GNAT. The code makes ample use of
dynamic allocation and threads.

I've tracked the problem down to simple memory allocation. Under
windows, it appears to me that the 'new' operator and the unchecked-
decallocate operations are using a task lock that is totally jamming
the system. A single threaded version of the windows code runs faster
than the dual-threaded version (on linux, I get a speed-up of a factor
close to 2). The sad fact is 99+% of the these allocations are local
and do not need to be shared across tasks. Ideally, i'd be able to
create a task-local memory pool that doesn't require a mutex for these
allocations.. not sure how feasible this is in Ada, though.

The obvious solution is to remove or minimize dynamic allocations but
I fear this isn't really practical. If it comes to this, so be it, but
I'd rather exhaust the other options first.

The other option is to replace the allocator with one of my own (or
someone elses), which brings me to my question: how! What I'd really
like to do is make a library that lets me replace the global allocator
a la libgmem. I struggled through the source code and makefiles of
GNAT and failed miserably in replicated it's function.

In a nut shell, what I want to be able to do is take System.Memory,
copy it, change a line of code (Put_Line("hello world")), and then be
able to replace the global allocator with this one. I was able to get
a replacement body for System.Memory to build with the gnatg flag, and
was able to get an o file, but whenever i make a simple test program
it automatically wants to put the original System.Memory in and I get
duplicate units if I try to bind them.

If anyone knows a more elegant solution to the actual problem, or has
any other advice, I'd love to hear it.




             reply	other threads:[~2007-07-25 16:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-25 16:11 ldb [this message]
2007-07-25 16:45 ` Problems with dynamic allocation in tasks Robert A Duff
2007-07-25 17:04   ` ldb
2007-07-25 17:25     ` Robert A Duff
2007-07-25 18:35     ` Dmitry A. Kazakov
2007-07-26 20:56 ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox