SmartHeap for Multi-Core

Size: px
Start display at page:

Download "SmartHeap for Multi-Core"

Transcription

1 SmartHeap for Multi-Core Getting Started and Platform Guide for Linux

2 Version 11.2

3 SmartHeap and HeapAgent are trademarks of Compuware Corporation. All other trademarks are the property of their respective holders. Copyright 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 NE 68th #102C Kirkland, Washington Voice: (425) Fax: (425) Internet: info@microquill.com

4

5 Contents Contents New in SmartHeap 11.x... 2 New in SmartHeap Introducing SmartHeap for Multi-Core... 2 New in SmartHeap New API controls thread-specific heap usage... 3 New in SmartHeap New in SmartHeap Improved design... 5 New tuning APIs... 6 Installing SmartHeap... 7 Files in the Linux SmartHeap release... 8 Using SmartHeap with Linux Getting started with the SmartHeap runtime library Adding the SmartHeap header file to your source files. 11 Specifying the location of SmartHeap files Linking with Runtime SmartHeap Debugging an application with SmartHeap Adding the Debug SmartHeap header file to your source files 14 Specifying the location of SmartHeap files Recompiling with Debug SmartHeap SmartHeap Linux platform notes Compiler functions that SmartHeap overrides SmartHeap for SMP Getting Started and Platform Guide Linux 1

6 New in SmartHeap 11.x Multi-threading in Linux Using SmartHeap with dynamically-loaded shared libraries 18 Using shared memory in SmartHeap for Linux Creating heaps in user-supplied regions SmartHeap Linux-specific values Default error handling for Linux 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

7 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

8 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

9 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

10 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

11 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

12 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

13 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

14 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

15 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

16 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

17 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

18 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

19 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

20 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

21 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 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

22 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

23 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

24 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

25 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

26 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 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 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

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

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 Heap Management The heap is the portion of the store that is used for data that lives indefinitely, or until the program explicitly deletes it. While local variables typically become inaccessible when

More information

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

In Java we have the keyword null, which is the value of an uninitialized reference type + More on Pointers + Null pointers In Java we have the keyword null, which is the value of an uninitialized reference type In C we sometimes use NULL, but its just a macro for the integer 0 Pointers are

More information

Memory Allocation in C

Memory Allocation in C Memory Allocation in C When a C program is loaded into memory, it is organized into three areas of memory, called segments: the text segment, stack segment and heap segment. The text segment (also called

More information

Advanced Memory Allocation

Advanced Memory Allocation Advanced Memory Allocation Call some useful functions of the GNU C library to save precious memory and to find nasty bugs. by Gianluca Insolvibile Dealing with dynamic memory traditionally has been one

More information

Processes. Johan Montelius KTH

Processes. Johan Montelius KTH Processes Johan Montelius KTH 2017 1 / 47 A process What is a process?... a computation a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

Reminder: compiling & linking

Reminder: compiling & linking Reminder: compiling & linking source file 1 object file 1 source file 2 compilation object file 2 library object file 1 linking (relocation + linking) load file source file N object file N library object

More information

A process. the stack

A process. the stack A process Processes Johan Montelius What is a process?... a computation KTH 2017 a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other processes

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

DYNAMIC MEMORY ALLOCATION ON REAL-TIME LINUX

DYNAMIC MEMORY ALLOCATION ON REAL-TIME LINUX DYNAMIC MEMORY ALLOCATION ON REAL-TIME LINUX Jianping Shen Institut Dr. Foerster GmbH und Co. KG In Laisen 70, 72766, Reutlingen, Germany shen.jianping@foerstergroup.de Michael Hamal Institut Dr. Foerster

More information

Unix System Programming - Chapter 2, part a

Unix System Programming - Chapter 2, part a Unix System Programming - Chapter 2, part a Neal Nelson The Evergreen State College Mar 23, 2010 USP Chapter 2.1 to 2.6 Processes and Threads Program Storage and Linkage Library Function Calls Error Handling

More information

Concurrency, Thread. Dongkun Shin, SKKU

Concurrency, Thread. Dongkun Shin, SKKU Concurrency, Thread 1 Thread Classic view a single point of execution within a program a single PC where instructions are being fetched from and executed), Multi-threaded program Has more than one point

More information

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

Chapter 1 GETTING STARTED. SYS-ED/ Computer Education Techniques, Inc. Chapter 1 GETTING STARTED SYS-ED/ Computer Education Techniques, Inc. Objectives You will learn: Java platform. Applets and applications. Java programming language: facilities and foundation. Memory management

More information

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

CSci 4061 Introduction to Operating Systems. Programs in C/Unix CSci 4061 Introduction to Operating Systems Programs in C/Unix Today Basic C programming Follow on to recitation Structure of a C program A C program consists of a collection of C functions, structs, arrays,

More information

Systems Programming/ C and UNIX

Systems Programming/ C and UNIX Systems Programming/ C and UNIX Alice E. Fischer Lecture 5 Makefiles October 2, 2017 Alice E. Fischer Lecture 5 Makefiles Lecture 5 Makefiles... 1/14 October 2, 2017 1 / 14 Outline 1 Modules and Makefiles

More information

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

XMEM. Extended C/C++ Dynamic Memory Control and Debug Library. XMEM Manual. Version 1.7 / September 2010 XMEM. Extended C/C++ Dynamic Memory Control and Debug Library XMEM Manual Version 1.7 / September 2010 Jürgen Müller reserves all rights including all industrial property rights. All rights of disposal

More information

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

o Code, executable, and process o Main memory vs. virtual memory Goals for Today s Lecture Memory Allocation Prof. David August COS 217 Behind the scenes of running a program o Code, executable, and process o Main memory vs. virtual memory Memory layout for UNIX processes,

More information

Project 3a: Malloc and Free

Project 3a: Malloc and Free Project 3a: Malloc and Free DUE 03/17 at 11:59 PM One late day allowed for submission without any penalty Objectives There are four objectives to this part of the assignment: Note To understand the nuances

More information

User created Heap Management in C on AIX

User created Heap Management in C on AIX Nitin.Bagoria User Created Heap Management in C on AIX Page 1 of 9 User created Heap Management in C on AIX Introduction The term heap, or memory heap, generally means a free memory pool, from which a

More information

Orbix TS Thread Library Reference

Orbix TS Thread Library Reference Orbix 6.3.9 TS Thread Library Reference Micro Focus The Lawn 22-30 Old Bath Road Newbury, Berkshire RG14 1QN UK http://www.microfocus.com Copyright Micro Focus 2017. All rights reserved. MICRO FOCUS, the

More information

Operating System Architecture. CS3026 Operating Systems Lecture 03

Operating System Architecture. CS3026 Operating Systems Lecture 03 Operating System Architecture CS3026 Operating Systems Lecture 03 The Role of an Operating System Service provider Provide a set of services to system users Resource allocator Exploit the hardware resources

More information

CS201- Introduction to Programming Current Quizzes

CS201- Introduction to Programming Current Quizzes CS201- Introduction to Programming Current Quizzes Q.1 char name [] = Hello World ; In the above statement, a memory of characters will be allocated 13 11 12 (Ans) Q.2 A function is a block of statements

More information

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

CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio Fall 2017 1 Outline Inter-Process Communication (20) Threads

More information

RCU in the Linux Kernel: One Decade Later

RCU in the Linux Kernel: One Decade Later RCU in the Linux Kernel: One Decade Later by: Paul E. Mckenney, Silas Boyd-Wickizer, Jonathan Walpole Slides by David Kennedy (and sources) RCU Usage in Linux During this same time period, the usage of

More information

CS201 Some Important Definitions

CS201 Some Important Definitions CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data

More information

C Structures & Dynamic Memory Management

C Structures & Dynamic Memory Management C Structures & Dynamic Memory Management Goals of this Lecture Help you learn about: Structures and unions Dynamic memory management Note: Will be covered in precepts as well We look at them in more detail

More information

Dynamic Memory Allocation

Dynamic Memory Allocation Dynamic Memory Allocation The process of allocating memory at run time is known as dynamic memory allocation. C does not Inherently have this facility, there are four library routines known as memory management

More information

CS61, Fall 2012 Section 2 Notes

CS61, Fall 2012 Section 2 Notes CS61, Fall 2012 Section 2 Notes (Week of 9/24-9/28) 0. Get source code for section [optional] 1: Variable Duration 2: Memory Errors Common Errors with memory and pointers Valgrind + GDB Common Memory Errors

More information

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

CSE 351, Spring 2010 Lab 7: Writing a Dynamic Storage Allocator Due: Thursday May 27, 11:59PM CSE 351, Spring 2010 Lab 7: Writing a Dynamic Storage Allocator Due: Thursday May 27, 11:59PM 1 Instructions In this lab you will be writing a dynamic storage allocator for C programs, i.e., your own version

More information

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

82V391x / 8V893xx WAN PLL Device Families Device Driver User s Guide 82V391x / 8V893xx WAN PLL Device Families Device Driver Version 1.2 April 29, 2014 Table of Contents 1. Introduction... 1 2. Software Architecture... 2 2.1. Overview... 2 2.2. Hardware Abstraction Layer

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #4 C Memory Management 2007-06-28 Scott Beamer, Instructor iphone Comes out Tomorrow CS61C L4 C Memory Management (1) www.apple.com/iphone

More information

pthreads CS449 Fall 2017

pthreads CS449 Fall 2017 pthreads CS449 Fall 2017 POSIX Portable Operating System Interface Standard interface between OS and program UNIX-derived OSes mostly follow POSIX Linux, macos, Android, etc. Windows requires separate

More information

ECE 15B COMPUTER ORGANIZATION

ECE 15B COMPUTER ORGANIZATION ECE 15B COMPUTER ORGANIZATION Lecture 13 Strings, Lists & Stacks Announcements HW #3 Due next Friday, May 15 at 5:00 PM in HFH Project #2 Due May 29 at 5:00 PM Project #3 Assigned next Thursday, May 19

More information

TS Thread Library Reference. Version 6.2, December 2004

TS Thread Library Reference. Version 6.2, December 2004 TS Thread Library Reference Version 6.2, December 2004 IONA, IONA Technologies, the IONA logo, Orbix, Orbix/E, Orbacus, Artix, Orchestrator, Mobile Orchestrator, Enterprise Integrator, Adaptive Runtime

More information

Oracle Berkeley DB. Porting Guide. Release 4.8

Oracle Berkeley DB. Porting Guide. Release 4.8 . Oracle Berkeley DB Porting Guide Release 4.8 Legal Notice This documentation is distributed under an open source license. You may review the terms of this license at: http://www.oracle.com/technology/software/products/berkeley-db/htdocs/oslicense.html

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

More information

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

Memory Allocation. Static Allocation. Dynamic Allocation. Dynamic Storage Allocation. CS 414: Operating Systems Spring 2008 Dynamic Storage Allocation CS 44: Operating Systems Spring 2 Memory Allocation Static Allocation (fixed in size) Sometimes we create data structures that are fixed and don t need to grow or shrink. Dynamic

More information

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

PROJECT 2 - MEMORY ALLOCATOR Computer Systems Principles. October 1, 2010 PROJECT 2 - MEMORY ALLOCATOR Computer Systems Principles Emery Berger Mark Corner October 1, 2010 1 Overview The purpose of this project is to acquaint you with how memory allocators provide virtual memory

More information

My malloc: mylloc and mhysa. Johan Montelius HT2016

My malloc: mylloc and mhysa. Johan Montelius HT2016 1 Introduction My malloc: mylloc and mhysa Johan Montelius HT2016 So this is an experiment where we will implement our own malloc. We will not implement the world s fastest allocator, but it will work

More information

Object-Oriented Programming for Scientific Computing

Object-Oriented Programming for Scientific Computing Object-Oriented Programming for Scientific Computing Dynamic Memory Management Ole Klein Interdisciplinary Center for Scientific Computing Heidelberg University ole.klein@iwr.uni-heidelberg.de 2. Mai 2017

More information

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

A program execution is memory safe so long as memory access errors never occur: A program execution is memory safe so long as memory access errors never occur: Buffer overflows, null pointer dereference, use after free, use of uninitialized memory, illegal free Memory safety categories

More information

Pointers, Dynamic Data, and Reference Types

Pointers, Dynamic Data, and Reference Types Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple

More information

Object-Oriented Programming

Object-Oriented Programming iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 1 / 37 Overview 1 2 3 4 5 2 / 37 Questions we will answer today What is the difference between the stack and the heap? How can we allocate and free memory

More information

Systems software design. Processes, threads and operating system resources

Systems software design. Processes, threads and operating system resources Systems software design Processes, threads and operating system resources Who are we? Krzysztof Kąkol Software Developer Jarosław Świniarski Software Developer Presentation based on materials prepared

More information

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

Base Component. Chapter 1. *Memory Management. Memory management Errors Exception Handling Messages Debug code Options Basic data types Multithreading Chapter 1. Base Component Component:, *Mathematics, *Error Handling, *Debugging The Base Component (BASE), in the base directory, contains the code for low-level common functionality that is used by all

More information

Release Note MPI/XMP-Linux Support Package

Release Note MPI/XMP-Linux Support Package 33 South La Patera Lane Santa Barbara, CA 93117-3214 ph (805) 681-3300 fax (805) 681-3311 tech@motioneng.com Release Note MPI/XMP-Linux Support Package MPI/XMP-Linux Library Version: 20030620.1.1 Revised

More information

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

Q1: /8 Q2: /30 Q3: /30 Q4: /32. Total: /100 ECE 2035(A) Programming for Hardware/Software Systems Fall 2013 Exam Three November 20 th 2013 Name: Q1: /8 Q2: /30 Q3: /30 Q4: /32 Total: /100 1/10 For functional call related questions, let s assume

More information

Dynamic Allocation of Memory

Dynamic Allocation of Memory Dynamic Allocation of Memory Lecture 4 Sections 10.9-10.10 Robb T. Koether Hampden-Sydney College Fri, Jan 25, 2013 Robb T. Koether (Hampden-Sydney College) Dynamic Allocation of Memory Fri, Jan 25, 2013

More information

Threads Chapter 5 1 Chapter 5

Threads Chapter 5 1 Chapter 5 Threads Chapter 5 1 Chapter 5 Process Characteristics Concept of Process has two facets. A Process is: A Unit of resource ownership: a virtual address space for the process image control of some resources

More information

Dynamic Data Structures. CSCI 112: Programming in C

Dynamic Data Structures. CSCI 112: Programming in C Dynamic Data Structures CSCI 112: Programming in C 1 It s all about flexibility In the programs we ve made so far, the compiler knows at compile time exactly how much memory to allocate for each variable

More information

Recitation #11 Malloc Lab. November 7th, 2017

Recitation #11 Malloc Lab. November 7th, 2017 18-600 Recitation #11 Malloc Lab November 7th, 2017 1 2 Important Notes about Malloc Lab Malloc lab has been updated from previous years Supports a full 64 bit address space rather than 32 bit Encourages

More information

Lectures 13 & 14. memory management

Lectures 13 & 14. memory management Lectures 13 & 14 Linked lists and memory management Courtesy of Prof. Garcia (UCB) CS61C L05 Introduction to C (pt 3) (1) Review Pointers and arrays are virtually same C knows how to increment pointers

More information

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

For Teacher's Use Only Q No Total Q No Q No Student Info Student ID: Center: Exam Date: FINALTERM EXAMINATION Spring 2010 CS201- Introduction to Programming Time: 90 min Marks: 58 For Teacher's Use Only Q No. 1 2 3 4 5 6 7 8 Total Marks Q No. 9

More information

Kurt Schmidt. October 30, 2018

Kurt Schmidt. October 30, 2018 to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed

More information

SPIN Operating System

SPIN Operating System SPIN Operating System Motivation: general purpose, UNIX-based operating systems can perform poorly when the applications have resource usage patterns poorly handled by kernel code Why? Current crop of

More information

Arrays, Pointers and Memory Management

Arrays, Pointers and Memory Management Arrays, Pointers and Memory Management EECS 2031 Summer 2014 Przemyslaw Pawluk May 20, 2014 Answer to the question from last week strct->field Returns the value of field in the structure pointed to by

More information

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

Outline. CS4254 Computer Network Architecture and Programming. Introduction 2/4. Introduction 1/4. Dr. Ayman A. Abdel-Hamid. Threads Dr. Ayman Abdel-Hamid, CS4254 Spring 2006 1 CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science Department Virginia Tech Threads Outline Threads (Chapter

More information

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

Outline. Threads. Single and Multithreaded Processes. Benefits of Threads. Eike Ritter 1. Modified: October 16, 2012 Eike Ritter 1 Modified: October 16, 2012 Lecture 8: Operating Systems with C/C++ School of Computer Science, University of Birmingham, UK 1 Based on material by Matt Smart and Nick Blundell Outline 1 Concurrent

More information

Introduction to PThreads and Basic Synchronization

Introduction to PThreads and Basic Synchronization Introduction to PThreads and Basic Synchronization Michael Jantz, Dr. Prasad Kulkarni Dr. Douglas Niehaus EECS 678 Pthreads Introduction Lab 1 Introduction In this lab, we will learn about some basic synchronization

More information

CSE 361S Intro to Systems Software Final Project

CSE 361S Intro to Systems Software Final Project Due: Tuesday, December 9, 2008. CSE 361S Intro to Systems Software Final Project In this project, you will be writing a dynamic storage allocator for C programs (i.e., your own version of malloc, free,

More information

Multitasking. Embedded Systems

Multitasking. Embedded Systems Multitasking in Embedded Systems 1 / 39 Multitasking in Embedded Systems v1.0 Multitasking in ES What is Singletasking? What is Multitasking? Why Multitasking? Different approaches Realtime Operating Systems

More information

CSE 333 Lecture 9 - storage

CSE 333 Lecture 9 - storage CSE 333 Lecture 9 - storage Steve Gribble Department of Computer Science & Engineering University of Washington Administrivia Colin s away this week - Aryan will be covering his office hours (check the

More information

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 CSC209 Review CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files ... and systems programming C basic syntax functions arrays structs

More information

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

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs. CSC209 Review CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files... and systems programming C basic syntax functions arrays structs

More information

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

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts. CPSC/ECE 3220 Fall 2017 Exam 1 Name: 1. Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.) Referee / Illusionist / Glue. Circle only one of R, I, or G.

More information

CSE 451 Midterm 1. Name:

CSE 451 Midterm 1. Name: CSE 451 Midterm 1 Name: 1. [2 points] Imagine that a new CPU were built that contained multiple, complete sets of registers each set contains a PC plus all the other registers available to user programs.

More information

Memory and C/C++ modules

Memory and C/C++ modules Memory and C/C++ modules From Reading #5 and mostly #6 More OOP topics (templates; libraries) as time permits later Program building l Have: source code human readable instructions l Need: machine language

More information

Concurrent & Distributed Systems Supervision Exercises

Concurrent & Distributed Systems Supervision Exercises Concurrent & Distributed Systems Supervision Exercises Stephen Kell Stephen.Kell@cl.cam.ac.uk November 9, 2009 These exercises are intended to cover all the main points of understanding in the lecture

More information

CP2 Revision. theme: dynamic datatypes & data structures

CP2 Revision. theme: dynamic datatypes & data structures CP2 Revision theme: dynamic datatypes & data structures structs can hold any combination of datatypes handled as single entity struct { }; ;

More information

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

ECEN 449 Microprocessor System Design. Hardware-Software Communication. Texas A&M University ECEN 449 Microprocessor System Design Hardware-Software Communication 1 Objectives of this Lecture Unit Learn basics of Hardware-Software communication Memory Mapped I/O Polling/Interrupts 2 Motivation

More information

Computer Systems A Programmer s Perspective 1 (Beta Draft)

Computer Systems A Programmer s Perspective 1 (Beta Draft) Computer Systems A Programmer s Perspective 1 (Beta Draft) Randal E. Bryant David R. O Hallaron August 1, 2001 1 Copyright c 2001, R. E. Bryant, D. R. O Hallaron. All rights reserved. 2 Contents Preface

More information

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

Fractal: A Software Toolchain for Mapping Applications to Diverse, Heterogeneous Architecures Fractal: A Software Toolchain for Mapping Applications to Diverse, Heterogeneous Architecures University of Virginia Dept. of Computer Science Technical Report #CS-2011-09 Jeremy W. Sheaffer and Kevin

More information

Project 2 Overview: Part A: User space memory allocation

Project 2 Overview: Part A: User space memory allocation Project 2 Overview: Once again, this project will have 2 parts. In the first part, you will get to implement your own user space memory allocator. You will learn the complexities and details of memory

More information

DAY 3. CS3600, Northeastern University. Alan Mislove

DAY 3. CS3600, Northeastern University. Alan Mislove C BOOTCAMP DAY 3 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh and Pascal Meunier s course at Purdue Memory management 2 Memory management Two

More information

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

Chapter 4: Threads. Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads Chapter 4: Threads Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads Chapter 4: Threads Objectives To introduce the notion of a

More information

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

Lecture 14. No in-class files today. Homework 7 (due on Wednesday) and Project 3 (due in 10 days) posted. Questions? Lecture 14 No in-class files today. Homework 7 (due on Wednesday) and Project 3 (due in 10 days) posted. Questions? Friday, February 11 CS 215 Fundamentals of Programming II - Lecture 14 1 Outline Static

More information

The C++ Object Lifecycle. EECS 211 Winter 2019

The C++ Object Lifecycle. EECS 211 Winter 2019 The C++ Object Lifecycle EECS 211 Winter 2019 2 Initial code setup $ cd eecs211 $ curl $URL211/lec/09lifecycle.tgz tar zx $ cd 09lifecycle 3 Road map Owned string type concept Faking it An owned string

More information

C++ for System Developers with Design Pattern

C++ for System Developers with Design Pattern C++ for System Developers with Design Pattern Introduction: This course introduces the C++ language for use on real time and embedded applications. The first part of the course focuses on the language

More information

The Art and Science of Memory Allocation

The Art and Science of Memory Allocation Logical Diagram The Art and Science of Memory Allocation Don Porter CSE 506 Binary Formats RCU Memory Management Memory Allocators CPU Scheduler User System Calls Kernel Today s Lecture File System Networking

More information

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

Dynamic Memory. Dynamic Memory Allocation Strings. September 18, 2017 Hassan Khosravi / Geoffrey Tien 1 Dynamic Memory Dynamic Memory Allocation Strings September 18, 2017 Hassan Khosravi / Geoffrey Tien 1 Pointer arithmetic If we know the address of the first element of an array, we can compute the addresses

More information

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

POSIX Threads: a first step toward parallel programming. George Bosilca POSIX Threads: a first step toward parallel programming George Bosilca bosilca@icl.utk.edu Process vs. Thread A process is a collection of virtual memory space, code, data, and system resources. A thread

More information

Class Information ANNOUCEMENTS

Class Information ANNOUCEMENTS Class Information ANNOUCEMENTS Third homework due TODAY at 11:59pm. Extension? First project has been posted, due Monday October 23, 11:59pm. Midterm exam: Friday, October 27, in class. Don t forget to

More information

IMPORTANT QUESTIONS IN C FOR THE INTERVIEW

IMPORTANT QUESTIONS IN C FOR THE INTERVIEW IMPORTANT QUESTIONS IN C FOR THE INTERVIEW 1. What is a header file? Header file is a simple text file which contains prototypes of all in-built functions, predefined variables and symbolic constants.

More information

Memory management. Johan Montelius KTH

Memory management. Johan Montelius KTH Memory management Johan Montelius KTH 2017 1 / 22 C program # include int global = 42; int main ( int argc, char * argv []) { if( argc < 2) return -1; int n = atoi ( argv [1]); int on_stack

More information

Lecture 8 Dynamic Memory Allocation

Lecture 8 Dynamic Memory Allocation Lecture 8 Dynamic Memory Allocation CS240 1 Memory Computer programs manipulate an abstraction of the computer s memory subsystem Memory: on the hardware side 3 @ http://computer.howstuffworks.com/computer-memory.htm/printable

More information

GFS: The Google File System

GFS: The Google File System GFS: The Google File System Brad Karp UCL Computer Science CS GZ03 / M030 24 th October 2014 Motivating Application: Google Crawl the whole web Store it all on one big disk Process users searches on one

More information

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

! What is main memory? ! What is static and dynamic allocation? ! What is segmentation? Maria Hybinette, UGA. High Address (0x7fffffff) ! Memory Questions? CSCI [4 6]730 Operating Systems Main Memory! What is main memory?! How does multiple processes share memory space?» Key is how do they refer to memory addresses?! What is static and dynamic

More information

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

CptS 360 (System Programming) Unit 2: Introduction to UNIX and Linux CptS 360 (System Programming) Unit 2: Introduction to UNIX and Linux Bob Lewis School of Engineering and Applied Sciences Washington State University Spring, 2018 Motivation APIs have a history: Learn

More information

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

Last week. Data on the stack is allocated automatically when we do a function call, and removed when we return Last week Data can be allocated on the stack or on the heap (aka dynamic memory) Data on the stack is allocated automatically when we do a function call, and removed when we return f() {... int table[len];...

More information

Guidelines for Writing C Code

Guidelines for Writing C Code Guidelines for Writing C Code Issue 01-bugfix Martin Becker Institute for Real-Time Computer Systems (RCS) Technische Universität München becker@rcs.ei.tum.de June 9, 2014 Contents 1 Introduction 1 2 Pragmatic

More information

High Performance Computing and Programming, Lecture 3

High Performance Computing and Programming, Lecture 3 High Performance Computing and Programming, Lecture 3 Memory usage and some other things Ali Dorostkar Division of Scientific Computing, Department of Information Technology, Uppsala University, Sweden

More information

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

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 3: Process. Zhi Wang Florida State University COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 3: Process Zhi Wang Florida State University Contents Process concept Process scheduling Operations on processes Inter-process communication

More information

CSE 374 Programming Concepts & Tools

CSE 374 Programming Concepts & Tools CSE 374 Programming Concepts & Tools Hal Perkins Fall 2017 Lecture 8 C: Miscellanea Control, Declarations, Preprocessor, printf/scanf 1 The story so far The low-level execution model of a process (one

More information

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

Process s Address Space. Dynamic Memory. Backing the Heap. Dynamic memory allocation 3/29/2013. When a process starts the heap is empty /9/01 Process s Address Space Dynamic Memory 0x7fffffff Stack Data (Heap) Data (Heap) 0 Text (Code) Backing the Heap When a process starts the heap is empty The process is responsible for requesting memory

More information

CS201: Lab #4 Writing a Dynamic Storage Allocator

CS201: Lab #4 Writing a Dynamic Storage Allocator CS201: Lab #4 Writing a Dynamic Storage Allocator In this lab you will write a dynamic storage allocator for C programs, i.e., your own version of the malloc, free and realloc routines. You are encouraged

More information

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

ECE454, Fall 2014 Homework3: Dynamic Memory Allocation Assigned: Oct 9th, Due: Nov 6th, 11:59PM ECE454, Fall 2014 Homework3: Dynamic Memory Allocation Assigned: Oct 9th, Due: Nov 6th, 11:59PM The TA for this assignment is Xu Zhao (nuk.zhao@mail.utoronto.ca). 1 Introduction OptsRus is doing really

More information

Inside the Garbage Collector

Inside the Garbage Collector Inside the Garbage Collector Agenda Applications and Resources The Managed Heap Mark and Compact Generations Non-Memory Resources Finalization Hindering the GC Helping the GC 2 Applications and Resources

More information

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

Memory Management. To do. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory Memory Management To do q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory Memory management Ideal memory for a programmer large, fast, nonvolatile and cheap not

More information

Last class: Today: Thread Background. Thread Systems

Last class: Today: Thread Background. Thread Systems 1 Last class: Thread Background Today: Thread Systems 2 Threading Systems 3 What kind of problems would you solve with threads? Imagine you are building a web server You could allocate a pool of threads,

More information

Lecture 10 Midterm review

Lecture 10 Midterm review Lecture 10 Midterm review Announcements The midterm is on Tue Feb 9 th in class 4Bring photo ID 4You may bring a single sheet of notebook sized paper 8x10 inches with notes on both sides (A4 OK) 4You may

More information