From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8bfa8c460ead1701,start X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!b79g2000hse.googlegroups.com!not-for-mail From: ldb Newsgroups: comp.lang.ada Subject: Problems with dynamic allocation in tasks Date: Wed, 25 Jul 2007 09:11:04 -0700 Organization: http://groups.google.com Message-ID: <1185379864.592973.73220@b79g2000hse.googlegroups.com> NNTP-Posting-Host: 206.210.81.55 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1185379864 15610 127.0.0.1 (25 Jul 2007 16:11:04 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 25 Jul 2007 16:11:04 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.4) Gecko/20061201 Firefox/2.0.0.4 (Ubuntu-feisty),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: b79g2000hse.googlegroups.com; posting-host=206.210.81.55; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Xref: g2news2.google.com comp.lang.ada:1173 Date: 2007-07-25T09:11:04-07:00 List-Id: 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.