@@ -43,6 +43,7 @@ CursorWindow::CursorWindow(size_t maxSize) :
43
43
// mData = (uint8_t *) memory->pointer();
44
44
// if (mData == NULL) {
45
45
// return false;
46
+
46
47
// }
47
48
// mHeader = (window_header_t *) mData;
48
49
@@ -121,39 +122,27 @@ LOG_WINDOW("Allocated row %u, rowSlot is at offset %u, fieldDir is %d bytes at o
121
122
122
123
uint32_t CursorWindow::alloc (size_t requestedSize, bool aligned)
123
124
{
124
- int32_t size;
125
+ size_t size = 0 , new_allocation_sz = 0 ;
125
126
uint32_t padding;
127
+ void *tempData = NULL ;
126
128
if (aligned) {
127
129
// 4 byte alignment
128
130
padding = 4 - (mFreeOffset & 0x3 );
129
131
} else {
130
132
padding = 0 ;
131
133
}
132
-
133
134
size = requestedSize + padding;
134
-
135
135
if (size > freeSpace ()) {
136
- LOGE (" need to grow: mSize = %d, size = %d, freeSpace() = %d, numRows = %d" , mSize , size, freeSpace (), mHeader ->numRows );
137
- // Only grow the window if the first row doesn't fit
138
- if (mHeader ->numRows > 1 ) {
139
- LOGE (" not growing since there are already %d row(s), max size %d" , mHeader ->numRows , mMaxSize );
140
- return 0 ;
141
- }
142
-
143
- // Find a new size that will fit the allocation
144
- int allocated = mSize - freeSpace ();
145
- int newSize = mSize + WINDOW_ALLOCATION_SIZE;
146
- while (size > (newSize - allocated)) {
147
- newSize += WINDOW_ALLOCATION_SIZE;
148
- if (newSize > mMaxSize ) {
149
- LOGE (" Attempting to grow window beyond max size (%d)" , mMaxSize );
150
- return 0 ;
151
- }
152
- }
153
- LOG_WINDOW (" found size %d" , newSize);
154
- mSize = newSize;
136
+ LOGE (" need to grow: mSize = %d, size = %d, freeSpace() = %d, numRows = %d" ,
137
+ mSize , size, freeSpace (), mHeader ->numRows );
138
+ new_allocation_sz = mSize + size - freeSpace ();
139
+ tempData = realloc ((void *)mData , new_allocation_sz);
140
+ if (tempData == NULL ) return 0 ;
141
+ mData = (uint8_t *)tempData;
142
+ mHeader = (window_header_t *)mData ;
143
+ LOGE (" allocation grew to:%d" , new_allocation_sz);
144
+ mSize = new_allocation_sz;
155
145
}
156
-
157
146
uint32_t offset = mFreeOffset + padding;
158
147
mFreeOffset += size;
159
148
return offset;
0 commit comments