9 memcpy(d, s, num_items * sizeof(Titem_)); |
9 memcpy(d, s, num_items * sizeof(Titem_)); |
10 } |
10 } |
11 |
11 |
12 |
12 |
13 /** Base class for simple binary blobs. |
13 /** Base class for simple binary blobs. |
14 Item is byte. |
14 * Item is byte. |
15 The word 'simple' means: |
15 * The word 'simple' means: |
16 - no configurable allocator type (always made from heap) |
16 * - no configurable allocator type (always made from heap) |
17 - no smart deallocation - deallocation must be called from the same |
17 * - no smart deallocation - deallocation must be called from the same |
18 module (DLL) where the blob was allocated |
18 * module (DLL) where the blob was allocated |
19 - no configurable allocation policy (how big blocks should be allocated) |
19 * - no configurable allocation policy (how big blocks should be allocated) |
20 - no extra ownership policy (i.e. 'copy on write') when blob is copied |
20 * - no extra ownership policy (i.e. 'copy on write') when blob is copied |
21 - no thread synchronization at all */ |
21 * - no thread synchronization at all */ |
22 class CBlobBaseSimple { |
22 class CBlobBaseSimple { |
23 protected: |
23 protected: |
24 struct CHdr { |
24 struct CHdr { |
25 int m_size; // actual blob size in bytes |
25 int m_size; // actual blob size in bytes |
26 int m_max_size; // maximum (allocated) size in bytes |
26 int m_max_size; // maximum (allocated) size in bytes |
76 if (!src.IsEmpty()) |
76 if (!src.IsEmpty()) |
77 memcpy(GrowRawSize(src.RawSize()), src.RawData(), src.RawSize()); |
77 memcpy(GrowRawSize(src.RawSize()), src.RawData(), src.RawSize()); |
78 } |
78 } |
79 |
79 |
80 /** Reallocate if there is no free space for num_bytes bytes. |
80 /** Reallocate if there is no free space for num_bytes bytes. |
81 @return pointer to the new data to be added */ |
81 * @return pointer to the new data to be added */ |
82 FORCEINLINE int8* MakeRawFreeSpace(int num_bytes) |
82 FORCEINLINE int8* MakeRawFreeSpace(int num_bytes) |
83 { |
83 { |
84 assert(num_bytes >= 0); |
84 assert(num_bytes >= 0); |
85 int new_size = RawSize() + num_bytes; |
85 int new_size = RawSize() + num_bytes; |
86 if (new_size > MaxRawSize()) SmartAlloc(new_size); |
86 if (new_size > MaxRawSize()) SmartAlloc(new_size); |
87 FixTail(); |
87 FixTail(); |
88 return ptr_u.m_pData + RawSize(); |
88 return ptr_u.m_pData + RawSize(); |
89 } |
89 } |
90 |
90 |
91 /** Increase RawSize() by num_bytes. |
91 /** Increase RawSize() by num_bytes. |
92 @return pointer to the new data added */ |
92 * @return pointer to the new data added */ |
93 FORCEINLINE int8* GrowRawSize(int num_bytes) |
93 FORCEINLINE int8* GrowRawSize(int num_bytes) |
94 { |
94 { |
95 int8* pNewData = MakeRawFreeSpace(num_bytes); |
95 int8* pNewData = MakeRawFreeSpace(num_bytes); |
96 RawSizeRef() += num_bytes; |
96 RawSizeRef() += num_bytes; |
97 return pNewData; |
97 return pNewData; |