RTI Connext Micro  Version 2.4.1.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
osapi_heap_impl.h
Go to the documentation of this file.
1 /*
2  * FILE: osapi_heap_impl.h - Implementation of HEAP API
3  *
4  * (c) Copyright, Real-Time Innovations, 2008-2014
5  *
6  * All rights reserved.
7  *
8  * No duplications, whole or partial, manual or electronic, may be made
9  * without express written permission. Any such copies, or
10  * revisions thereof, must display this notice unaltered.
11  * This code contains trade secrets of Real-Time Innovations, Inc.
12  *
13  * Modification History
14  * --------------------
15  * 22sep2008,tk Created
16  */
17 /*ce \file
18  * \brief Macro implementing heap interface
19  */
20 #ifndef osapi_heap_impl_h
21 #define osapi_heap_impl_h
22 
23 #ifndef osapi_dll_h
24 #include "osapi/osapi_dll.h"
25 #endif
26 
27 #include "osapi/osapi_config.h"
28 
29 #ifdef HAVE_MALLOC_H
30 #include <malloc.h>
31 #else
32 #include <stdlib.h>
33 #endif
34 
35 #if (OSAPI_PLATFORM != OSAPI_PLATFORM_POSIX)
36 /* For OSAPI_PLATFORM_POSIX, this function has been moved to posixHeap.c
37  * #define OSAPI_Heap_allocate(a, b) OSAPI_Heap_allocate_func(a, b)
38  */
39 #define OSAPI_Heap_allocate(a, b) calloc(a, b);OSAPI_gv_AllocatedByteCount+=(a)*(b)
40 #endif
41 
42 #ifdef RTI_CERT
43 #define OSAPI_Heap_free(a)
44 #define OSAPI_Heap_realloc(ptr_,size_)
45 #else
46 #define OSAPI_Heap_free(a) free(a)
47 #define OSAPI_Heap_realloc(ptr_,size_) realloc(ptr_,size_)
48 #endif
49 
50 /*--------------------------------------------------------------------------*/
51 /* This needs to stay a MACRO; not for performance reasons but because
52  it is the only way to pass a "type" into the "function"
53  */
54 #define OSAPI_Heap_allocate_struct(dest_, type_) \
55  *(dest_) = (type_ *)OSAPI_Heap_allocate(1, sizeof(type_))
56 /*--------------------------------------------------------------------------*/
57 #ifndef RTI_CERT
58 #define OSAPI_Heap_free_struct(dest_) \
59  if ((dest_) != NULL) OSAPI_Heap_free(dest_)
60 #else
61 #define OSAPI_Heap_free_struct(dest_)
62 #endif
63 /*--------------------------------------------------------------------------*/
64 /* This needs to stay a MACRO; not for performance reasons but because
65  it is the only way to pass a "type" into the "function"
66  */
67 #define OSAPI_Heap_allocate_array(dest_, count_, type_) \
68  *(dest_) = (type_ *)OSAPI_Heap_allocate(count_,sizeof(type_))
69 /*--------------------------------------------------------------------------*/
70 #ifndef RTI_CERT
71 #define OSAPI_Heap_free_array(dest_) \
72  if ((dest_) != NULL) OSAPI_Heap_free(dest_)
73 #else
74 #define OSAPI_Heap_free_array(dest_)
75 #endif
76 /*--------------------------------------------------------------------------*/
77 #define OSAPI_Heap_allocate_string(string_, size_) \
78  *(string_) = (char *)OSAPI_Heap_allocate((size_)+1, 1)
79 /*--------------------------------------------------------------------------*/
80 #ifndef RTI_CERT
81 #define OSAPI_Heap_free_string(string_) \
82  if ((string_) != NULL) OSAPI_Heap_free(string_)
83 #else
84 #define OSAPI_Heap_free_string(string_)
85 #endif
86 /*--------------------------------------------------------------------------*/
87 
88 #endif /* osapi_heap_impl_h */

RTI Connext Micro Version 2.4.1.0 Copyright © Thu Nov 20 2014 Real-Time Innovations, Inc