Funky new problems?

This is a discussion on Funky new problems? within the C++ Programming forums, part of the General Programming Boards category; im not elite with C++(this does not apply to my C knowledge) but on occasion I use the operator new ...

  1. #1
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267

    Funky new problems?

    im not elite with C++(this does not apply to my C knowledge) but on occasion I use the operator new instead of *alloc, and i stangely get Illegal Operations which can be better illistrated with a text example!

    ok, i have a functioning class in it i allocate memory which is used through-out the program and deleted in the destructor. i use new being sure to allocate enough memory(eg. the exact size to be used), when i "delete" the memory or after the program exits i get an illegal operation, but heres the catch if i allocate a bunch more memory it doesn't happen! so you say "hes overwriting the memory and causing it not to delete properly" which is what i thought at first, then i checked it out and I wasn't so i replaced it with a call to malloc and released it with free with the exact code as with the new and it works!

    so im i using new improperly or do i suffer a compiler implementation bug?
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  2. #2
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330
    That happens to me too, and I'm not sure why...

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Have you a, (short), program which demonstrates the effect you could post. I'll try it and see if it is a compiler issue, (probably not!), or if I can see if you're doing something wrong.

    I don't tend to have this problem.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    I'm assuming here, but are you overloading the new operator?

    There can be problems if you overload new and then release the memory with a call to the standard operator delete......

    If you are overloading new, then overload delete as well.....

    As I said I am assuming here....

  5. #5
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    >I'll try it and see if it is a compiler issue, (probably not!), or if I can see if you're doing something wrong.

    im assuming it's me,


    this is a snippet from part of a program that loads a lwo(3D file) into memory,

    where chunksize is declared

    int chunksize = 0;

    and later has a value of 120(bytes)

    PointList is declared in the class like so

    float* PointList;

    PointList = new float[chunksize/4];

    for(int i = 0;i < chunksize/4;i++)
    {
    fread(&PointList[i],4,1,CurrentFile);
    ReverseBits(&PointList[i],4,1);
    }

    and is deleted like this

    if(PointList != NULL)
    delete[] PointList;

    well when i used this i got illegal operation on program close, but since this debugger can act a little funny it may also be the delete.
    im using malloc() with the SAME EXACT code and its fine.

    well **** now i try it with new and its fine, must be a compiler bug...or im retarded(more likely)...
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 05:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 04:48 PM
  4. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 03:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21