SmartHeap for Multi-Core

Similar documents
Heap Management portion of the store lives indefinitely until the program explicitly deletes it C++ and Java new Such objects are stored on a heap

In Java we have the keyword null, which is the value of an uninitialized reference type

Memory Allocation in C

Advanced Memory Allocation

Processes. Johan Montelius KTH

Short Notes of CS201

Reminder: compiling & linking

A process. the stack

CS201 - Introduction to Programming Glossary By

DYNAMIC MEMORY ALLOCATION ON REAL-TIME LINUX

Unix System Programming - Chapter 2, part a

Concurrency, Thread. Dongkun Shin, SKKU

Chapter 1 GETTING STARTED. SYS-ED/ Computer Education Techniques, Inc.

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

Systems Programming/ C and UNIX

XMEM. Extended C/C++ Dynamic Memory Control and Debug Library. XMEM Manual. Version 1.7 / September 2010

o Code, executable, and process o Main memory vs. virtual memory

Project 3a: Malloc and Free

User created Heap Management in C on AIX

Orbix TS Thread Library Reference

Operating System Architecture. CS3026 Operating Systems Lecture 03

CS201- Introduction to Programming Current Quizzes

CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio

RCU in the Linux Kernel: One Decade Later

CS201 Some Important Definitions

C Structures & Dynamic Memory Management

Dynamic Memory Allocation

CS61, Fall 2012 Section 2 Notes

CSE 351, Spring 2010 Lab 7: Writing a Dynamic Storage Allocator Due: Thursday May 27, 11:59PM

82V391x / 8V893xx WAN PLL Device Families Device Driver User s Guide

CS61C : Machine Structures

pthreads CS449 Fall 2017

ECE 15B COMPUTER ORGANIZATION

TS Thread Library Reference. Version 6.2, December 2004

Oracle Berkeley DB. Porting Guide. Release 4.8

A Fast Review of C Essentials Part I

Memory Allocation. Static Allocation. Dynamic Allocation. Dynamic Storage Allocation. CS 414: Operating Systems Spring 2008

PROJECT 2 - MEMORY ALLOCATOR Computer Systems Principles. October 1, 2010

My malloc: mylloc and mhysa. Johan Montelius HT2016

Object-Oriented Programming for Scientific Computing

A program execution is memory safe so long as memory access errors never occur:

Pointers, Dynamic Data, and Reference Types

Object-Oriented Programming

Systems software design. Processes, threads and operating system resources

Base Component. Chapter 1. *Memory Management. Memory management Errors Exception Handling Messages Debug code Options Basic data types Multithreading

Release Note MPI/XMP-Linux Support Package

Q1: /8 Q2: /30 Q3: /30 Q4: /32. Total: /100

Dynamic Allocation of Memory

Threads Chapter 5 1 Chapter 5

Dynamic Data Structures. CSCI 112: Programming in C

Recitation #11 Malloc Lab. November 7th, 2017

Lectures 13 & 14. memory management

For Teacher's Use Only Q No Total Q No Q No

Kurt Schmidt. October 30, 2018

SPIN Operating System

Arrays, Pointers and Memory Management

Outline. CS4254 Computer Network Architecture and Programming. Introduction 2/4. Introduction 1/4. Dr. Ayman A. Abdel-Hamid.

Outline. Threads. Single and Multithreaded Processes. Benefits of Threads. Eike Ritter 1. Modified: October 16, 2012

Introduction to PThreads and Basic Synchronization

CSE 361S Intro to Systems Software Final Project

Multitasking. Embedded Systems

CSE 333 Lecture 9 - storage

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.

CSE 451 Midterm 1. Name:

Memory and C/C++ modules

Concurrent & Distributed Systems Supervision Exercises

CP2 Revision. theme: dynamic datatypes & data structures

ECEN 449 Microprocessor System Design. Hardware-Software Communication. Texas A&M University

Computer Systems A Programmer s Perspective 1 (Beta Draft)

Fractal: A Software Toolchain for Mapping Applications to Diverse, Heterogeneous Architecures

Project 2 Overview: Part A: User space memory allocation

DAY 3. CS3600, Northeastern University. Alan Mislove

Chapter 4: Threads. Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads

Lecture 14. No in-class files today. Homework 7 (due on Wednesday) and Project 3 (due in 10 days) posted. Questions?

The C++ Object Lifecycle. EECS 211 Winter 2019

C++ for System Developers with Design Pattern

The Art and Science of Memory Allocation

Dynamic Memory. Dynamic Memory Allocation Strings. September 18, 2017 Hassan Khosravi / Geoffrey Tien 1

POSIX Threads: a first step toward parallel programming. George Bosilca

Class Information ANNOUCEMENTS

IMPORTANT QUESTIONS IN C FOR THE INTERVIEW

Memory management. Johan Montelius KTH

Lecture 8 Dynamic Memory Allocation

GFS: The Google File System

! What is main memory? ! What is static and dynamic allocation? ! What is segmentation? Maria Hybinette, UGA. High Address (0x7fffffff) !

CptS 360 (System Programming) Unit 2: Introduction to UNIX and Linux

Last week. Data on the stack is allocated automatically when we do a function call, and removed when we return

Guidelines for Writing C Code

High Performance Computing and Programming, Lecture 3

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 3: Process. Zhi Wang Florida State University

CSE 374 Programming Concepts & Tools

Process s Address Space. Dynamic Memory. Backing the Heap. Dynamic memory allocation 3/29/2013. When a process starts the heap is empty

CS201: Lab #4 Writing a Dynamic Storage Allocator

ECE454, Fall 2014 Homework3: Dynamic Memory Allocation Assigned: Oct 9th, Due: Nov 6th, 11:59PM

Inside the Garbage Collector

Memory Management. To do. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Last class: Today: Thread Background. Thread Systems

Lecture 10 Midterm review

Transcription:

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: info@microquill.com

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 SmartHeap for SMP Getting Started and Platform Guide Linux 1

New in SmartHeap 11.x 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. 2 SmartHeap for SMP Getting Started and Platform Guide Linux

Files in the Linux SmartHeap release 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: SmartHeap for SMP Getting Started and Platform Guide Linux 3

New in SmartHeap 8.0 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. 4 SmartHeap for SMP Getting Started and Platform Guide Linux

Files in the Linux SmartHeap release 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. SmartHeap for SMP Getting Started and Platform Guide Linux 5

New in SmartHeap 6 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. 6 SmartHeap for SMP Getting Started and Platform Guide Linux

Files in the Linux SmartHeap release 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. SmartHeap for SMP Getting Started and Platform Guide Linux 7

Installing SmartHeap 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 8 SmartHeap for SMP Getting Started and Platform Guide Linux

Files in the Linux SmartHeap release 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 SmartHeap for SMP Getting Started and Platform Guide Linux 9

Installing SmartHeap 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 10 SmartHeap for SMP Getting Started and Platform Guide Linux

Getting started with the SmartHeap runtime library 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). SmartHeap for SMP Getting Started and Platform Guide Linux 11

Using SmartHeap with 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 12 SmartHeap for SMP Getting Started and Platform Guide Linux

Getting started with the SmartHeap runtime library 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 A 32-bit single-threaded C application A 32-bit single-threaded C++ application A 64-bit single-threaded C application A 64-bit single-threaded C++ application A 32-bit multi-threaded C application A 32-bit multi-threaded C++ application A 64-bit multi-threaded C application A 64-bit multi-threaded C++ application If you re statically linking SmartHeap with A 32-bit single-threaded C application A 32-bit single-threaded C++ application A 64-bit single-threaded C application A 64-bit single-threaded C++ application A 32-bit multi-threaded C application A 32-bit multi-threaded C++ application A 64-bit multi-threaded C application A 64-bit multi-threaded C++ application Link with these libraries libsmartheap.so libsmartheap.so, libsmartheapc.a libsmartheap64.so libsmartheap64.so, libsmartheapc64.a libsmartheap_core.so libsmartheap_core.so, libsmartheapc_core.a libsmartheap_core64.so libsmartheap_core64.so, libsmartheapc_core64.a Link with these libraries libsmartheap.a libsmartheap.a, LibsmartheapC.a libsmartheap64.a libsmartheap64.a, LibsmartheapC64.a libsmartheap_core.a libsmartheap_core.a, libsmartheapc_core.a libsmartheap_core64.a libsmartheap_core64.a, libsmartheapc_core64.a SmartHeap for SMP Getting Started and Platform Guide Linux 13

Using SmartHeap with 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 memoryallocation 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. 14 SmartHeap for SMP Getting Started and Platform Guide Linux

Debugging an application with SmartHeap 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 SmartHeap for SMP Getting Started and Platform Guide Linux 15

Using SmartHeap with Linux If you re using the SmartHeap shared library with A 32-bit single-threaded C application A 32-bit single-threaded C++ application A 64-bit single-threaded C application A 64-bit single-threaded C++ application A 32-bit multi-threaded C application A 32-bit multi-threaded C++ application A 64-bit multi-threaded C application A 64-bit multi-threaded C++ application 2. Add the Debug SmartHeap Library before any other libraries, to your linker command line. If you re statically linking SmartHeap with A 32-bit single-threaded C application A 32-bit single-threaded C++ application A 64-bit single-threaded C application A 64-bit single-threaded C++ application A 32-bit multi-threaded C application A 32-bit multi-threaded C++ application A 64-bit multi-threaded C application A 64-bit multi-threaded C++ application Link with these libraries libsmartheapd.so libsmartheapd.so, LibsmartheapCd.a libsmartheapd64.so libsmartheapd64.so, LibsmartheapCd64.a libsmartheap_mtd.so libsmartheap_mtd.so, LibsmartheapC_mtd.a libsmartheap_mtd64.so libsmartheap_mtd64.so, LibsmartheapC_mtd64.a Link with these libraries libsmartheapd.a libsmartheapd.a, LibsmartheapCd.a libsmartheapd64.a libsmartheapd64.a, LibsmartheapCd64.a libsmartheap_mtd.a libsmartheap_mtd.a, LibsmartheapC_mtd.a libsmartheap_mtd64.a libsmartheap_mtd64.a, LibsmartheapC_mtd64.a 3. Run your make file to rebuild your application, for example: make /f myapp.mak 16 SmartHeap for SMP Getting Started and Platform Guide Linux

Compiler functions that SmartHeap overrides 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; 17 SmartHeap for SMP Getting Started and Platform Guide Linux

SmartHeap Linux platform notes 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. 18 SmartHeap for SMP Getting Started and Platform Guide Linux

Using shared memory in SmartHeap for Linux 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 for SMP Getting Started and Platform Guide Linux 19

SmartHeap Linux platform notes 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. 20 SmartHeap for SMP Getting Started and Platform Guide Linux

Creating heaps in user-supplied regions 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 for SMP Getting Started and Platform Guide Linux 21

SmartHeap Linux platform notes 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). 22 SmartHeap for SMP Getting Started and Platform Guide Linux