Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F19250794
allocators.hh
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
allocators.hh
View Options
#ifndef NPSTAT_ALLOCATORS_HH_
#define NPSTAT_ALLOCATORS_HH_
/*!
// \file allocators.hh
//
// \brief Utilities related to memory management
//
// Author: I. Volobouev
//
// October 2009
*/
#include
<cassert>
namespace
npstat
{
/**
// Function for allocating memory buffers if their size
// exceeds the size of the buffer available on the stack
*/
template
<
typename
T
>
inline
T
*
makeBuffer
(
unsigned
sizeNeeded
,
T
*
stackBuffer
,
unsigned
sizeofStackBuffer
)
{
if
(
sizeNeeded
>
sizeofStackBuffer
||
stackBuffer
==
0
)
return
new
T
[
sizeNeeded
];
else
return
stackBuffer
;
}
/** Function for freeing memory buffers allocated by "makeBuffer" */
template
<
typename
T
>
inline
void
destroyBuffer
(
T
*
thisBuffer
,
const
T
*
stackBuffer
)
{
if
(
thisBuffer
!=
stackBuffer
)
delete
[]
thisBuffer
;
}
/** Copy a buffer (with possible type conversion on the fly) */
template
<
typename
T1
,
typename
T2
>
inline
void
copyBuffer
(
T1
*
dest
,
const
T2
*
source
,
const
unsigned
long
len
)
{
if
(
len
)
{
assert
(
dest
);
assert
(
source
);
for
(
unsigned
long
i
=
0
;
i
<
len
;
++
i
)
*
dest
++
=
static_cast
<
T1
>
(
*
source
++
);
}
}
/**
// Clear a buffer (set all elements to the value produced by the
// default constructor)
*/
template
<
typename
T
>
inline
void
clearBuffer
(
T
*
buf
,
const
unsigned
long
len
)
{
if
(
len
)
{
assert
(
buf
);
const
T
zero
=
T
();
for
(
unsigned
long
i
=
0
;
i
<
len
;
++
i
)
*
buf
++
=
zero
;
}
}
}
#endif
// NPSTAT_ALLOCATORS_HH_
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Tue, Sep 30, 5:44 AM (10 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6566319
Default Alt Text
allocators.hh (1 KB)
Attached To
Mode
rNPSTATSVN npstatsvn
Attached
Detach File
Event Timeline
Log In to Comment