Hi Nikolay,
On 9/25/10 10:16 PM, Nikolay Sivov wrote:
Store user defined request headers on transaction beginning
+ buff = CoTaskMemAlloc((size+1)*sizeof(WCHAR)); + if (!buff) return E_OUTOFMEMORY; + + LIST_FOR_EACH_ENTRY(entry,&This->request->reqheaders, struct reqheader, entry) + { + LONG header_size = SysStringLen(entry->header) + SysStringLen(entry->value) + 4 /* colon, space, CRLF */; + + /* get large enough buffer */ + while (freech< header_size) + { + WCHAR *buff2; + + freech += size; + size *= 2; + buff2 = CoTaskMemRealloc(buff, (size+1)*sizeof(WCHAR));
This is very inefficient. You can compute header size before doing allocation, so that no reallocation is needed. And even when doing reallocation, the inner loop may be easily avoided.
Jacek