using delete to delete an array

This is a discussion on using delete to delete an array within the C++ Programming forums, part of the General Programming Boards category; ok - im confused i have an array that recieves a 16 bit data packet from the com port char ...

  1. #1
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385

    using delete to delete an array

    ok - im confused

    i have an array that recieves a 16 bit data packet from the com port
    char rxPacket[16];

    when i evaluate the packet to check for a good checksum - if it has a bad checksum i need to erase the data. It gets passed to the function deletebadPacket();

    in which i try to delete the array using

    delete[] rxPacket ;

    according to my help reference this is legal syntax but throws a memory violation every time - does this deinitialize the array or just erase its content.

    tia
    Monday - what a way to spend a seventh of your life

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    You can only delete things you created with new.

    You cannot delete arrays you declared this way. Your best choice is to overwrite it with zeros to mark it as empty.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    or use new to create rxPacket?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. delete array of arrays
    By tmod in forum C++ Programming
    Replies: 4
    Last Post: 04-17-2007, 03:37 PM
  3. Delete duplicate items in an array
    By chaos in forum C Programming
    Replies: 4
    Last Post: 06-16-2005, 02:51 PM
  4. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 12:01 AM
  5. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 11:09 AM

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