1 mike 1.1 /*
2 **==============================================================================
3 **
4 ** Open Management Infrastructure (OMI)
5 **
6 ** Copyright (c) Microsoft Corporation
7 **
8 ** Licensed under the Apache License, Version 2.0 (the "License"); you may not
9 ** use this file except in compliance with the License. You may obtain a copy
10 ** of the License at
11 **
12 ** http://www.apache.org/licenses/LICENSE-2.0
13 **
14 ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 ** MERCHANTABLITY OR NON-INFRINGEMENT.
18 **
19 ** See the Apache 2 License for the specific language governing permissions
20 ** and limitations under the License.
21 **
22 mike 1.1 **==============================================================================
23 */
24
25 #ifndef _omi_alloc_h
26 #define _omi_alloc_h
27
28 #include "config.h"
29 #include <common.h>
30 #include "batch.h"
31
32 BEGIN_EXTERNC
33
34 MI_INLINE void* BAlloc(
35 Batch* batch,
36 size_t size,
37 CallSite callSite)
38 {
39 MI_UNUSED(callSite);
40 return Batch_Get(batch, size);
41 }
42
43 mike 1.1 MI_INLINE void BFree(
44 Batch* batch,
45 void* ptr,
46 CallSite callSite)
47 {
48 MI_UNUSED(callSite);
49 Batch_Put(batch, ptr);
50 }
51
52 MI_INLINE void* BRealloc(
53 Batch* batch,
54 void* ptr,
55 size_t oldSize,
56 size_t newSize,
57 CallSite callSite)
58 {
59 if (!ptr)
60 return Batch_Get(batch, newSize);
61 else
62 {
63 void* p = Batch_Get(batch, newSize);
64 mike 1.1 MI_UNUSED(callSite);
65
66 if (!p)
67 return NULL;
68
69 if (oldSize < newSize)
70 {
71 memcpy(p, ptr, oldSize);
72 memset((char*)p + oldSize, 0, newSize - oldSize);
73 }
74 else
75 memcpy(p, ptr, newSize);
76
77 return p;
78 }
79 }
80
81 MI_INLINE void* BCalloc(
82 Batch* batch,
83 size_t size,
84 CallSite callSite)
85 mike 1.1 {
86 MI_UNUSED(callSite);
87 return Batch_GetClear(batch, size);
88 }
89
90 MI_INLINE MI_Char* BStrdup(
91 Batch* batch,
92 const MI_Char* str,
93 CallSite callSite)
94 {
95 MI_UNUSED(callSite);
96 return Batch_Zdup(batch, str);
97 }
98
99 END_EXTERNC
100
101 #endif /* _omi_alloc_h */
|