void* MemoryPoolStaticMalloc::realloc(void *p_memory,size_t p_bytes) {

	#if DEFAULT_ALIGNMENT == 1

		return _realloc(p_memory,p_bytes);
	#else
		if (!p_memory)
			return alloc(p_bytes);

		int total = p_bytes + DEFAULT_ALIGNMENT;
		uint8_t* mem = (uint8_t*)p_memory;
		int ofs = *(mem-1);
		mem = mem - ofs;
		uint8_t* ptr = (uint8_t*)_realloc(mem, total);
		ERR_FAIL_COND_V(ptr == NULL, NULL);
		int new_ofs = (DEFAULT_ALIGNMENT - ((uintptr_t)ptr & (DEFAULT_ALIGNMENT - 1)));
		if (new_ofs != ofs) {

			//printf("realloc moving %i bytes\n", p_bytes);
			movemem((ptr + new_ofs), (ptr + ofs), p_bytes);
			ptr[new_ofs-1] = new_ofs;
		};
		return ptr + new_ofs;
	#endif
};
Beispiel #2
0
static char *my_realloc(char *from, int nsize, int osize)
{
  char *tmp;
  tmp=malloc(nsize);
  movemem(from, tmp, osize);
  free(from);
  return tmp;
}
Beispiel #3
0
static int is_end_of_headers(char *s, int len)
{
  if(!headers) 
  {
    hsize = (len/1024+1)*1024;
    headers = malloc(hsize);
    hpointer = 0;
  } else if(hsize <= hpointer+len) {
    headers = my_realloc(headers, hsize*2, hsize);
    hsize *= 2;
  }

  movemem((headers+hpointer), s, len);
  hpointer += len;
  headers[hpointer] = 0;

  return (strstr(headers, "\n\n")
	  || strstr(headers,"\r\n\r\n")
	  || strstr(headers, "\n\r\n\r"));
}