[Gc] Reallocating strings.

jim marshall jim.marshall at wbemsolutions.com
Thu Jul 5 19:32:42 PDT 2007


S M Ryan wrote:
> I think I saw a web page on the best way to resize strings which was 
> something other than just doubling each time. But I cannot find that 
> again. If there is better alternative to doubling, could someone point 
> it out?
I think I know what you are referring to, 
http://www.hpl.hp.com/personal/Hans_Boehm/gc/debugging.html (under the 
section 'Warning Messages About Needing to Allocate Blacklisted 
Blocks'). This is the realloc function we came up with based on the 
feedback on that page:

void* reallocMemory(void* vptr, size_t elSize)
{
    size_t old_size = GC_size(vptr);
    void * result = NULL;

    if (elSize <= old_size)
    {
      result = vptr;
    } else if (elSize <= 10240) {
      result = GC_REALLOC(vptr, elSize);
    } else {
      result = GC_MALLOC_IGNORE_OFF_PAGE(elSize);
      if (result != 0)
      {
        memcpy(result, vptr, old_size);
        GC_FREE(vptr);
      }
    }
    return result;
}

HTH
Jim
> _______________________________________________
> Gc mailing list
> Gc at linux.hpl.hp.com
> http://www.hpl.hp.com/hosted/linux/mail-archives/gc/
>
>
>


More information about the Gc mailing list