+ All Categories
Home > Documents > Setting up HeapAgent if you’re using - Whidbey Telecom MC 11 for Linux.pdf · MicroQuill Software...

Setting up HeapAgent if you’re using - Whidbey Telecom MC 11 for Linux.pdf · MicroQuill Software...

Date post: 15-Jul-2018
Category:
Upload: phungnguyet
View: 215 times
Download: 0 times
Share this document with a friend
26
SmartHeap for Multi-Core Getting Started and Platform Guide for Linux
Transcript

SmartHeap™ for

Multi-Core Getting Started and Platform Guide for

Linux

Version 11.2

SmartHeap and HeapAgent are trademarks of Compuware Corporation. All other trademarks are the property of their respective holders.

Copyright ©1994-2015 Compuware Corporation. All rights reserved.

We’d like to have your ideas and comments about this manual. Your suggestions help us improve our products. Please send comments to:

MicroQuill Software Publishing, Inc. 10512 NE 68th #102C Kirkland, Washington 98033

Voice: (425) 827-7200 Fax: (425) 650-7150 Internet: [email protected]

SmartHeap for SMP Getting Started and Platform Guide — Linux 1

Contents

Contents

New in SmartHeap 11.x .......................................................... 2 

New in SmartHeap 10.0 .......................................................... 2 Introducing SmartHeap for Multi-Core ......................... 2 

New in SmartHeap 8.0 ............................................................ 3 New API controls thread-specific heap usage ............... 3 

New in SmartHeap 7 ............................................................... 5 

New in SmartHeap 6 ............................................................... 5 Improved design ............................................................ 5 New tuning APIs ........................................................... 6 

Installing SmartHeap .............................................................. 7 Files in the Linux SmartHeap release ................................... 8 

Using SmartHeap with Linux ................................................. 11 Getting started with the SmartHeap runtime library ............. 11 

Adding the SmartHeap header file to your source files . 11 Specifying the location of SmartHeap files ................... 12 Linking with Runtime SmartHeap ................................. 13 

Debugging an application with SmartHeap .......................... 14 Adding the Debug SmartHeap header file to your source files 14 Specifying the location of SmartHeap files ................... 15 Recompiling with Debug SmartHeap ............................ 15 

SmartHeap Linux platform notes ........................................... 17 Compiler functions that SmartHeap overrides .............. 17 

New in SmartHeap 11.x

2 SmartHeap for SMP Getting Started and Platform Guide — Linux

Multi-threading in Linux ............................................... 18 Using SmartHeap with dynamically-loaded shared libraries 18 Using shared memory in SmartHeap for Linux ............. 19 Creating heaps in user-supplied regions ........................ 21 SmartHeap Linux-specific values .................................. 22 Default error handling for Linux ................................... 22 

New in SmartHeap 11.x For an overview of what's new in recent versions of SmartHeap (11.0 and later), including the latest release, please see "ReleaseNotes.txt" in the root directory of your SmartHeap installation.

New in SmartHeap 10.0

Introducing SmartHeap for Multi-Core SmartHeap 10.0 introduces a new multi-threaded library designed specifically for todays multi-core processors. New performance optimizations make SmartHeap 10 up to 3x faster than version 9 when run on a single CPU with two or more cores. The performance improvement is only available with Microsoft Windows and Linux, operating systems that run on the Intel/AMD multi core design.

Files in the Linux SmartHeap release

SmartHeap for SMP Getting Started and Platform Guide — Linux 3

Note that these performance improvements, and those described below under New in SmartHeap 8.0, are available only when running on systems that use a single-physical processor . They are enabled on systems with two or more physical processors only in the SmartHeap/SMP product.

New in SmartHeap 8.0

The SmartHeap 8.0 multi-threaded libraries contain performance optimizations making them up to 2x faster than version 7. The performance improvement is greatest on the Windows operating system.

Note that the general performance improvements in SmartHeap version 8, and those described under MemDefaultPoolThreadExclusive, below, are available only when running on single-processor (including hyperthread-enabled Intel processor) systems. The performance enhancements are enabled on SMP systems only in the SmartHeap/SMP product.

New API controls thread-specific heap usage SmartHeap 8.0 introduces a new API, MemDefaultPoolThreadExclusive, that can be used to greatly enhance performance and simplify heap object deallocation in applications that use heap exclusively in one or more threads. Applications that will benefit from this new API are those that have one or more heap-intensive threads which exclusively free the memory they allocate.

Use MemDefaultPoolThreadExclusive only in threads that exclusively free all heap pointers that are allocated by that thread after the call to MemDefaultPoolThreadExclusive.

The new API has the following prototype:

New in SmartHeap 8.0

4 SmartHeap for SMP Getting Started and Platform Guide — Linux

MEM_BOOL MemDefaultPoolThreadExclusive(unsigned flags);

Specify one of the following values for flags:

• MEM_THREAD_EXCLUSIVE_OFF: default behavior – current thread uses process-wide default memory pool. Heap operations are synchronized with other threads.

• MEM_THREAD_EXCLUSIVE_ON: creates thread-specific default memory pool for the current thread. Synchronization with other threads is not needed, resulting in improved performance. Specify this value only if all allocations created with malloc, calloc, new, or realloc in the calling thread are freed exclusively by the same thread. Can be combined disjunctively with MEM_FREE_ON_THREAD_TERM.

• MEM_FREE_ON_THREAD_TERM: creates thread-specific default memory pool for the current thread. All allocations created in the current thread are automatically freed at thread termination, simplifying and improving performance of storage management. Note that you still must calls delete for objects created with operator new in order for destructors to execute, though you can override operator delete for such objects with an empty operator delete definition if desired (if the objects are used exclusively in thread-specific memory pools) since SmartHeap will automatically free the memory at thread termination. Specify this value only if all allocations created with malloc, calloc, new, or realloc in the calling thread are either not freed or are freed exclusively by the same thread, and if there are no references to allocations created in the calling thread from other threads after the calling thread terminates. Can be combined disjunctively with MEM_THREAD_EXCLUSIVE_ON.

Call this API from each thread where you want one or both of the above behaviors.

Files in the Linux SmartHeap release

SmartHeap for SMP Getting Started and Platform Guide — Linux 5

New in SmartHeap 7 • Version 7 introduces SmartHeap for 64-bit Linux. This new

platform is fully supported with both debug and runtime libraries.

• SmartHeap 7 also supports Intel’s hyperthreading technology.

• SmartHeap 7 offers better better memory utilization with little or no performance penalty. More memory and address space is returned to the operating system when no longer in use, and there is a new API (MemProcessUseMunmap) to aggressively return address space on Solaris, DEC UNIX, Linux and SGI.

• The default sub-alloc threshold has been raised from 16K to a little under 64K. This design should use less memory in most cases, and particularly when a lot of blocks in the range of 16K to 64K are allocated. A new API (MemPoolSetMaxSubAlloc) lets you tune the suballoc threshold when appropriate.

New in SmartHeap 6

Improved design SmartHeap 6.0 offers better absolute speed and better memory utilization. Unlike SmartHeap 5, it returns memory to the OS, and the user can control both how much is returned and when it is returned.

New in SmartHeap 6

6 SmartHeap for SMP Getting Started and Platform Guide — Linux

A new API is introduced in SmartHeap 6.0 primarily for the benefit of UNIX valloc and memalign. MemAllocAligned (MEM_POOL pool, unsigned long size, unsigned long alignment, unsigned flags) is identical to MemAllocPtr except that the result is aligned to a multiple of the value specified in the “alignment” parameter.

New tuning APIs Several new tuning APIs are introduced in this release:

• void MemProcessSetFreeBytes(unsigned long bytes) controls how much free space SmartHeap maintains in the large block heap. In SmartHeap 5 this was infinite (memory was never returned to the OS). In SmartHeap 6 the user can control exactly when SmartHeap returns memory to the OS via this API. The default value is 10MB, meaning that SmartHeap won’t start releasing memory to the OS until the large block heap has more than 10MB of free space. Larger values result in better allocation performance but larger process footprint.

• void MemProcessSetLargeBlockThreshold (unsigned long bytes) controls the block size SmartHeap manages in its large block heap. The default size is 512KB. Blocks larger than the threshold value are allocated by the OS and freed directly to the OS. Larger values result in better performance but potentially larger process footprint.

• unsigned long MemPoolSetFreeBytes(MEM_POOL pool, unsigned long bytes) controls free space in a pool just as MemProcessSetFreeBytes controls free space in the large block heap. The default value is 1MB. Large values result in better performance and less contention at the expense of more space for allocations less than 16K in size. When this value is non-zero, SmartHeap leaves empty pages, up to the aggregate size specified, inside the pool. When a pool needs to add a page it can do so without a global lock or a large-block heap allocation by recycling a page previously freed by the same pool.

Files in the Linux SmartHeap release

SmartHeap for SMP Getting Started and Platform Guide — Linux 7

Installing SmartHeap The files on the SmartHeap installation media are not copy protected. To install SmartHeap on your hard disk:

1. Identify the directory you want to install SmartHeap in, create that directory (if necessary) and cd to it.

For example, if you want to install SmartHeap in /opt/sh, enter the following commands: mkdir /opt/sh

cd /opt/sh

2. Insert the SmartHeap media into your installation device and copy the SmartHeap archive files with the following command: tar xpvf device_name

where device_name is the name of your installation device (for example, /dev/fd0).

3. Unzip the SmartHeap files with the following command: gunzip *.gz

4. Unarchive each file that ends with the .tar extension as follows: tar xpvf filename.tar

5. Add the SmartHeap include directory to your compiler’s header file search path, and add the SmartHeap lib directory to your linker’s library search path.

Installing SmartHeap

8 SmartHeap for SMP Getting Started and Platform Guide — Linux

Files in the Linux SmartHeap release This SmartHeap release supports Red Hat Linux 7 through 9, and RHEL 3 and 4 Included are statically linkable and shared libraries, platform-independent header files, and platform-independent source files for the malloc and C++ operator new definitions. Both single- and multi-thread SmartHeap libraries are included.

The following files are present on the SmartHeap distribution media:

Directory File Description include smrtheap.h Header file containing all Runtime

SmartHeap C declarations except malloc include smrtheap.hpp Header file containing Runtime SmartHeap

C++ declarations, including operator new

include shmalloc.h Header file containing declarations for Runtime SmartHeap ANSI C functions (malloc, etc.)

lib libsmartheap.a 32-bit single-thread runtime SmartHeap C Linux archive library

lib libsmartheapC.a 32-bit single-thread runtime SmartHeap C++ Linux archive library

lib libsmartheap.so 32-bit single-thread runtime SmartHeap Linux shared library

lib libsmartheap_core.a 32-bit multi-thread runtime SmartHeap C Linux archive library

lib libsmartheapC_core.a 32-bit multi-thread runtime SmartHeap C++ Linux archive library

lib libsmartheap_core.so 32-bit multi-thread runtime SmartHeap Linux shared library

lib libsmartheapd.a 32-bit single-thread debug SmartHeap C Linux archive library

lib libsmartheapCd.a 32-bit single-thread debug SmartHeap C++ Linux archive library

Directory File Description

Files in the Linux SmartHeap release

SmartHeap for SMP Getting Started and Platform Guide — Linux 9

lib libsmartheapd.so 32-bit single-thread debug SmartHeap Linux shared library

lib libsmartheap_mtd.a 32-bit multi-thread Debug SmartHeap Linux C archive library

lib libsmartheapC_mtd.a 32-bit multi-thread Debug SmartHeap C++ Linux archive library

lib libsmartheap_mtd.so 32-bit multi-thread Debug SmartHeap Linux shared library

lib libsmartheap_smpd.so 32-bit multi-thread smp debug SmartHeap Linux shared library

lib libsmartheap_smpd.a 32-bit multi-thread smp debug SmartHeap Linux archive library

lib libsmartheapC_smpd.a 32-bit multi-thread smp debug SmartHeap Linux C++ archive library

lib64 libsmartheap64.a 64-bit single-thread runtime SmartHeap C Linux archive library

lib64 libsmartheapC64.a 64-bit single-thread runtime SmartHeap C++ Linux archive library

lib64 libsmartheap64.so 64-bit single-thread runtime SmartHeap Linux shared library

lib64 libsmartheap_core64.a 64-bit multi-thread runtime SmartHeap C Linux archive library

lib64 libsmartheapC_core64.a 64-bit multi-thread runtime SmartHeap C++ Linux archive library

lib64 libsmartheap_core64.so 64-bit multi-thread runtime SmartHeap Linux shared library

lib64 libsmartheapd64.a 64-bit single-thread debug SmartHeap C Linux archive library

lib64 libsmartheapCd64.a 64-bit single-thread debug SmartHeap C++ Linux archive library

lib64 libsmartheapd64.so 64-bit single-thread debug SmartHeap Linux shared library

lib64 libsmartheap_mtd64.a 64-bit multi-thread Debug SmartHeap Linux C archive library

lib64 libsmartheapC_mtd64.a 64-bit multi-thread Debug SmartHeap C++ Linux archive library

Installing SmartHeap

10 SmartHeap for SMP Getting Started and Platform Guide — Linux

lib64 libsmartheap_mtd64.so 64-bit multi-thread Debug SmartHeap Linux shared library

lib64 libsmartheap_smpd64.so 64-bit multi-thread smp debug SmartHeap Linux shared library

lib64 libsmartheap_smpd64.a 64-bit multi-thread smp debug SmartHeap Linux archive library

lib64 libsmartheap_smpd64.so 64-bit multi-thread smp debug SmartHeap Linux C++ archive library

Getting started with the SmartHeap runtime library

SmartHeap for SMP Getting Started and Platform Guide — Linux 11

Using SmartHeap with Linux Here’s how to get started with SmartHeap on Linux.

Getting started with the SmartHeap runtime library

Here’s how you set up your application to use the SmartHeap runtime library. For information on debugging your application with Debug SmartHeap, see “Debugging an application with SmartHeap,” later in this section.

Adding the SmartHeap header file to your source files Important! If you’re not calling SmartHeap APIs, skip to the next page. You don’t need to add SmartHeap header files if you simply want SmartHeap to replace malloc and operator new.

For each file that makes SmartHeap API calls:

♦ For C source files, include smrtheap.h, which contains declarations for the C SmartHeap APIs.

#include <smrtheap.h>

♦ For C++ source files, include smrtheap.hpp, which contains declarations for SmartHeap versions of operator new and which itself includes smrtheap.h.

#include <smrtheap.hpp>

In both cases, the #include directive must appear after any compiler or library header files that declare malloc (for example, stdlib.h) or new (for example, new.h).

Using SmartHeap with Linux

12 SmartHeap for SMP Getting Started and Platform Guide — Linux

Specifying the location of SmartHeap files To tell your compiler where to find SmartHeap include and library files:

1. Add the SmartHeap include directory to your compiler’s include path, or specify this directory on the compiler command line, for example: -I/opt/sh/include

2. Add the SmartHeap lib (lib64 for 64-bit libs) directory to your linker’s library path, or specify this directory on the linker command line, for example: -L/opt/sh/lib

Getting started with the SmartHeap runtime library

SmartHeap for SMP Getting Started and Platform Guide — Linux 13

Linking with Runtime SmartHeap To relink your application with Runtime SmartHeap:

1. Add the Runtime SmartHeap Library after all object files, but before any other libraries, to your linker command line.

If you’re using the SmartHeap shared library with Link with these libraries A 32-bit single-threaded C application libsmartheap.so

A 32-bit single-threaded C++ application libsmartheap.so, libsmartheapC.a

A 64-bit single-threaded C application libsmartheap64.so

A 64-bit single-threaded C++ application libsmartheap64.so, libsmartheapC64.a

A 32-bit multi-threaded C application libsmartheap_core.so

A 32-bit multi-threaded C++ application libsmartheap_core.so, libsmartheapC_core.a

A 64-bit multi-threaded C application libsmartheap_core64.so

A 64-bit multi-threaded C++ application libsmartheap_core64.so, libsmartheapC_core64.a

If you’re statically linking SmartHeap with Link with these libraries A 32-bit single-threaded C application libsmartheap.a

A 32-bit single-threaded C++ application libsmartheap.a, LibsmartheapC.a

A 64-bit single-threaded C application libsmartheap64.a

A 64-bit single-threaded C++ application libsmartheap64.a, LibsmartheapC64.a

A 32-bit multi-threaded C application libsmartheap_core.a

A 32-bit multi-threaded C++ application libsmartheap_core.a, libsmartheapC_core.a

A 64-bit multi-threaded C application libsmartheap_core64.a

A 64-bit multi-threaded C++ application libsmartheap_core64.a, libsmartheapC_core64.a

Using SmartHeap with Linux

14 SmartHeap for SMP Getting Started and Platform Guide — Linux

2. Run your make file to relink your application, for example: make /f myapp.mak

Debugging an application with SmartHeap Here’s how you set up your application for debugging with Debug SmartHeap.

Adding the Debug SmartHeap header file to your source files If you want to call Debug SmartHeap APIs (dbgMemXXX), you’ll need to include the Debug SmartHeap header file and recompile your application.

Note Simply linking with the Debug SmartHeap Library is sufficient to allow SmartHeap to perform full error detection, but in most cases you’ll also want to recompile your application so that SmartHeap includes source file names and line numbers in its error reports.

For each file from which you call Debug SmartHeap APIs:

♦ Include heapagnt.h, which contains declarations of memory-allocation functions both for ANSI C (malloc, free, and so on) and for C++ (including the new and delete operators). The #include directive must appear after any compiler or library header files that declare malloc (for example, stdlib.h) or new (for example, new.h):

#include <heapagnt.h>

Note If you already include smrtheap.h, shmalloc.h, or smrtheap.hpp, then you don’t need to also include heapagnt.h. The Runtime SmartHeap header files automatically include heapagnt.h when MEM_DEBUG is defined.

Debugging an application with SmartHeap

SmartHeap for SMP Getting Started and Platform Guide — Linux 15

Specifying the location of SmartHeap files To tell your compiler where to find Debug SmartHeap include and library files:

1. Add the SmartHeap include directory to your compiler’s include path, or specify this directory on the compiler command line, for example: -I/opt/sh/include

2. Add the SmartHeap lib (lib64 for 64-bit libs) directory to your linker’s library path, or specify this directory on the linker command line, for example: -L/opt/sh/lib

Recompiling with Debug SmartHeap To recompile and relink your application with Debug SmartHeap:

1. Add the following options to your compiler command line: -DMEM_DEBUG=1 -DDEFINE_NEW_MACRO=1

Using SmartHeap with Linux

16 SmartHeap for SMP Getting Started and Platform Guide — Linux

2. Add the Debug SmartHeap Library before any other libraries, to your linker command line.

If you’re using the SmartHeap shared library with Link with these libraries A 32-bit single-threaded C application libsmartheapd.so

A 32-bit single-threaded C++ application libsmartheapd.so, LibsmartheapCd.a

A 64-bit single-threaded C application libsmartheapd64.so

A 64-bit single-threaded C++ application libsmartheapd64.so, LibsmartheapCd64.a

A 32-bit multi-threaded C application libsmartheap_mtd.so

A 32-bit multi-threaded C++ application libsmartheap_mtd.so, LibsmartheapC_mtd.a

A 64-bit multi-threaded C application libsmartheap_mtd64.so

A 64-bit multi-threaded C++ application libsmartheap_mtd64.so, LibsmartheapC_mtd64.a

If you’re statically linking SmartHeap with Link with these libraries A 32-bit single-threaded C application libsmartheapd.a

A 32-bit single-threaded C++ application libsmartheapd.a, LibsmartheapCd.a

A 64-bit single-threaded C application libsmartheapd64.a

A 64-bit single-threaded C++ application libsmartheapd64.a, LibsmartheapCd64.a

A 32-bit multi-threaded C application libsmartheap_mtd.a

A 32-bit multi-threaded C++ application libsmartheap_mtd.a, LibsmartheapC_mtd.a

A 64-bit multi-threaded C application libsmartheap_mtd64.a

A 64-bit multi-threaded C++ application libsmartheap_mtd64.a, LibsmartheapC_mtd64.a

3. Run your make file to rebuild your application, for example: make /f myapp.mak

Compiler functions that SmartHeap overrides

17 SmartHeap for SMP Getting Started and Platform Guide — Linux

SmartHeap Linux platform notes

Compiler functions that SmartHeap overrides SmartHeap overrides malloc, calloc, realloc, free, new, and delete on all platforms, as explained in §2.3.2, §2.3.3, and §2.3.4 in the SmartHeap Programmer’s Guide.

Note If you do not want SmartHeap to override operator new and delete, simply omit the SmartHeap C++ library (libsmartheapCxxx.a) when linking your application.

If you don’t want SmartHeap to override one or more of these functions, you should remove the applicable object module from the SmartHeap libraries. For example, use the following command to prevent SmartHeap from overriding malloc with the statically linked Runtime SmartHeap library: ar d libsmartheap.a shmalloc.o

If you remove the shmalloc.o object module from a SmartHeap library, you’ll need to define SmartHeap_malloc at file scope. For example: int SmartHeap_malloc = 0;

SmartHeap Linux platform notes

18 SmartHeap for SMP Getting Started and Platform Guide — Linux

Multi-threading in Linux The SmartHeap libraries in this release are fully thread-reentrant (MT-safe). If you link SmartHeap with an application that creates multiple threads, make sure to call MemRegisterTask before starting the second thread.

Caution! SmartHeap 6.0 does not initialize its heap mutexes until you call MemRegisterTask. Therefore, if your program does not call MemRegisterTask before creating its second thread, memory allocation calls will not be serialized, which will almost certainly result in heap corruption.

For the SmartHeap/Linux thread-reentrant libraries, the default memory pool (used by malloc and new) is always serialized, unless you define MemDefaultPoolFlags to disable serialization. Memory pools you create with MemPoolInit[FS] are not serialized unless you supply either MEM_POOL_DEFAULT or MEM_POOL_SERIALIZE with the flags parameter.

If you use a given memory pool in only one thread at any time, do not supply MEM_POOL_DEFAULT or MEM_POOL_SERIALIZE when initializing the memory pool, or performance will suffer needlessly.

Using SmartHeap with dynamically-loaded shared libraries If you link SmartHeap with a shared library that is dynamically loaded by another application, malloc will most likely already be bound to CRT malloc before your shared library is loaded. As a result, your shared library will call CRT malloc even though it has linked with SmartHeap malloc.

If you are building such as shared library, specify –Bsymbolic to ld when linking your shared library to ensure that the shared library uses SmartHeap rather than CRT malloc at runtime.

Using shared memory in SmartHeap for Linux

SmartHeap for SMP Getting Started and Platform Guide — Linux 19

Using shared memory in SmartHeap for Linux Beginning in version 3.0, SmartHeap supports UNIX shared memory. SmartHeap uses the shared memory and semaphore facilities of the standard InterProcess Communication (IPC) package to implement shared memory pools.

Use MemPoolInitNamedShared to create shared memory pools. The name parameter to MemPoolInitNamedShared must be a valid shared memory object key, according to UNIX conventions. Use ftok() to create a key, and cast the result to (const char *) when passing to MemPoolInitNamedShared. The flags parameter implicitly includes MEM_POOL_SHARED and MEM_POOL_SERIALIZE, so you do not need to specify these two flags.

The size parameter to MemPoolInitNamedShared specifies the total size of the underlying UNIX shared memory segment. This cannot be resized once the memory pool is created. Specify the total amount of memory you wish to make available to the memory pool.

When determining the pool size, keep in mind that each memory pool requires 4K of space for internal data structures and that free space occupies, on average, one third of the total space in a memory pool. Therefore, if X is the maximum number of bytes you will allocate, specify a pool size of at least X * 2 + 4K. You can use the MemPoolSize function to determine the actual memory in use in a pool, and use this as a guideline for the size parameter. Note that Debug SmartHeap uses more memory than Runtime SmartHeap to store debugging state.

Shared memory pools are always serialized with inter-process synchronization mutual exclusion. You can concurrently allocate blocks from a shared pool from multiple processes with complete safety.

Once a shared memory pool has been created, you can access it from other processes by calling MemPoolAttachShared and specifying the shared pool name. Always pass NULL as the pool parameter for UNIX.

SmartHeap Linux platform notes

20 SmartHeap for SMP Getting Started and Platform Guide — Linux

The MemPoolInitNamedShared call must have returned in the original process before MemPoolAttachShared will succeed in another process. The reason for this restriction is that the semaphore that provides for serialization is stored in the shared memory object — there can be no guarantee that the semaphore has been initialized and stored in the shared memory object until the shared memory object itself has been initialized.

You can call MemPoolAttachShared concurrently from as many processes as you like once MemPoolInitNamedShared has returned.

You can use all of the SmartHeap allocation and de-allocation APIs with shared memory pools. In Debug SmartHeap, shared memory pools fully support all of the same debugging facilities as private memory pools.

If SmartHeap detects an error such an overwrite in a shared pool, the error is reported to the process in which the error is detected, regardless of where the shared memory pool was created.

In Debug SmartHeap, when you compile your source files with MEM_DEBUG, SmartHeap stores a pointer to the source file name in each allocated memory block. The actual file name is a string constant, generated by the compiler, that exists only in the current process. For shared memory pools, SmartHeap copies file name strings into space owned by the shared memory pool, so the file names are accessible from all processes that attach to the pool. Only the first 19 characters of file names are stored, so if you allocate shared memory from source files having longer names, the file names reported in memory error reports will be truncated to the first 19 characters.

To end access to a shared pool from a given process, call MemPoolFree from that process. The shared pool will continue to exist until every process that has access to it calls MemPoolFree. The process that creates a shared pool does not need to be the last process to call MemPoolFree; the shared pool is not owned by a particular process.

Creating heaps in user-supplied regions

SmartHeap for SMP Getting Started and Platform Guide — Linux 21

Creating heaps in user-supplied regions The SmartHeap API MemPoolInitRegion is now supported in Linux and other UNIX platforms in SmartHeap 5.0 and higher. MemPoolInitRegion allows you to create a memory pool within a region of memory you supply.

For details about this API, see the entry for MemPoolInitRegion in §4.2, “Function reference,” in the SmartHeap Programmer’s Guide.

SmartHeap Linux platform notes

22 SmartHeap for SMP Getting Started and Platform Guide — Linux

SmartHeap Linux-specific values The following are some platform-specific defaults and attributes for this version of SmartHeap (all values in bytes, non-debug version of SmartHeap; all values subject to change in future versions):

Description 32bit 64bit Related API Default page size 64K 64K MemPoolSetPageSize Default small block threshold 20 40 MemPoolSetBlockSizeFS Per-alloc overhead, FS blocks 0 0 MemAllocFS Per-alloc overhead, blocks < 256 bytes 0 0 MemAllocPtr, malloc, new Per-alloc overhead, var ptr blocks 4 8 MemAllocPtr, malloc, new Granularity, FS blocks 8 8 MemAllocFS Granularity, blocks < 256 bytes 4 8 MemAllocPtr, malloc, new Granularity, all others 8 8 MemAllocPtr Minimum block size, FS blocks 8 8 MemAllocFS Minimum block size, all others 4 8 MemAllocPtr Per-page overhead, all APIs 56 112 Minimum page size 64K 64K MemPoolSetPageSize Maximum page size 64K 64K MemPoolSetPageSize Size of empty memory pool 64K 64K MemPoolInit[FS]

Default error handling for Linux The default error handler in the Linux version of SmartHeap prompts with “Abort, Ignore [, Retry]” to stderr. Retry is present only for recoverable errors.

If you type: • “a” for Abort, SmartHeap calls the abort function, which

terminates the application. • “i” for Ignore, the SmartHeap function that reported the error

returns with an error return value. • “r” for Retry, SmartHeap retries the operation (for example,

attempts a memory allocation again).


Recommended