BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
DistBoss/DistBossUtil/DistBossUtil-00-00-04/DistBossUtil/AutoEnlargeBuffer.h
Go to the documentation of this file.
1#ifndef AUTO_ENLARGE_BUFFER_H
2#define AUTO_ENLARGE_BUFFER_H
3
4#include <stdlib.h>
5#include <string.h> //for memcpy
6
8{
9 public :
10
11 inline AutoEnlargeBuffer(int size = 128*1024);
12
13 inline ~AutoEnlargeBuffer();
14
15 inline void copy(void *src, int size);
16
17 inline int size() { return m_size; }
18 inline void *data() { return m_buffer; }
19
20
21 private :
22
23 int m_SIZE;
24 int m_size;
25 void* m_buffer;
26};
27
29 : m_SIZE( size ),
30 m_size( 0 )
31{
32 m_buffer = malloc(size);
33}
34
36{
37 free( m_buffer );
38}
39
40inline void AutoEnlargeBuffer::copy(void *src, int size)
41{
42 if ( size > m_SIZE ) {
43 do {
44 m_SIZE *= 2;
45 }
46 while ( size > m_SIZE );
47
48 free( m_buffer );
49 m_buffer = malloc(m_SIZE);
50 }
51
52 m_size = size;
53 memcpy(m_buffer, src, size);
54}
55
56#endif