Search:

Type: Posts; User: Salem

Search: Search took 0.29 seconds.

  1. Thread: oparator new

    by Salem
    Replies
    24
    Views
    5,463

    Yes, that should be fine - well, no memory leaks...

    Yes, that should be fine - well, no memory leaks anyway.

    Though later on, you might want to introduce a 'maxsize' as well, so you can re-use the buffer if newsize <= maxsize
  2. Thread: oparator new

    by Salem
    Replies
    24
    Views
    5,463

    > So in Salem's example we should "delete [] t"...

    > So in Salem's example we should "delete [] t" also at the end of every loop?
    No you wouldn't.



    new
    for ( .... ) {
    new
    ....
    delete
  3. Thread: oparator new

    by Salem
    Replies
    24
    Views
    5,463

    You're not reallocating anything at the moment. ...

    You're not reallocating anything at the moment.

    You need to start with something like
    char *s = new char[1];
    *s = '\0';

    Then each loop iteration is
    char *t = new char[i+1];
    strcpy(t,s);...
  4. Thread: oparator new

    by Salem
    Replies
    24
    Views
    5,463

    Try strcpy instead of strcat. The memory you...

    Try strcpy instead of strcat.

    The memory you get is uninitialised, and the first thing strcat does is go looking for a \0.
    Your memory is filled with junk, so this is a crap-shoot as to what...
Results 1 to 4 of 5