Will we get SEGV if we try to ?delete []? un-initialized integer pointer va

I have a class with an integer pointer, which I have not initialized to NULL in the constructor. For example:
class myclass
private:
char * name;
int *site;
myclass:: myclass(?.)
: name(NULL)
other member function "delete [] " the variable before initializing it.
Ex:
void myclass:: copy_site ( int **Values, int *from)
int *old;
old = *values.
Delete [] old; <<<<<? here I am getting SEGV
But I am getting SEGV at "delete []".
Surprisingly it is not happening every time.For some inputs it is certainly working fine.
What could be the reason?
If it is because of initialization, why is working for some inputs and certainly not for other inputs?
I have observed with workshop that, for some inputs it is automatically getting initialized to NULL, and for other inputs it is certainly not NULL (dangling pointer).
Thanks in advance,
Suresh

The rule for "delete"is that you must write
delete [] p;
if p points to an array, but you must write
delete p; // without []
if p points to a single object.
Therefore, you must know how how the heap item that p points to was created: as a single object or as an array.
If you guess wrong, your code is likely to fail. The exact circumstances when you get a failure depend on the details of your code and on the details of the compiler implementation. The C++ standard says that the results are "undefined", meaning that you are not allowed to expect any particular result.
If p could reasonably be assigned the address of either a single object or an array, you need to change your allocation strategy.
1. Never allocate a single object, but always allocate an array, even if an array of 1 item.
2. Use "delete []", since you will always have an array.
You could create a factory function that returns a pointer to an array of T (even if an array of 1 object) and call that function instead of allocating directly on the heap.
But it's more likely that you can organize your code so that you always know whether you are dealing with an arary or a heap. The problem of p versus p[0] to get to the object is still there.

Similar Messages

  • Apps get stucked when i try to delete them?

    Whenever i try to delete an app by holding the icon and waiting for the apps to start jiggle then hit the X button, it does nothing but get stuck. After a while it gets back to normal and the app is still there. I know i can delete them by going in Settings - Usage and look for the app but that's not the point. I've never had this problem. It started when i updated my software to 5.0. It ****** me off cuz most of the games are still in Game Center can't get rid of them and whenever i redownload them it takes me back where i have left off. Any ideas?

    Hello elnvlj,
    Thanks for using Apple Support Communities.
    For more information on this, take a look at:
    Appears frozen or unresponsive
    iOS: Not responding or does not turn on
    http://support.apple.com/kb/TS3281
    Best of luck,
    Mario

  • Will i get all my apps bk after updating to ios5

    ive just upgraded to IOS5! All my apps are gone as are all my music, videos etc! WILL I GET THEM BACK?

    try syncing it to iTunes one more time.  when I upgraded my old iphone, it did several steps before all the apps were on it.  When it is hooked up, see if iTunes expects the apps to be loaded on the phone by checking the apps page in iTunes.
    If that doesn't work:  Do you have a back up of your previous phone with the apps?   If so, hook the phone back up to iTunes and choose the restore option and when asked whether to make it a new phone or restore from back-up, select the last known backup that had apps.
    It should bring everything back.

  • HT3209 If I purchase an iTunes movie and try to play it back through my computer/tv via and hdmi connection, will I get sound only through my computer?

    If I purchase an iTunes movie and try to play it back through my computer/tv via and hdmi connection, will I get sound only through my computer?

    Welcome to the Apple Community.
    Only through iTunes/Quicktime and only if the TV supports HDCP.

  • I want to get a Nikon D3100, but my macbook has OS 10.5.5 on it and I've read that the D3100 needs at least 10.6.5. What will happen if I try to use this camera with my computer? Will iPhoto simply not recognize it or will I get distorted pictures, or..?

    I want to get a Nikon D3100, but my macbook has OS 10.5.5 on it and I've read that the D3100 needs at least 10.6.5. What will happen if I try to use this camera with my computer? Will iPhoto simply not recognize it or will I get distorted pictures, or....what?

    andyBall_uk wrote:
    The manual says
    ❚❚ Supported Operating Systems The supplied software can be used with computers running the following operating systems: •          Windows: <snip>
    •          Macintosh: Mac OS X (version 10.4.11, 10.5.8, 10.6.4)
    Nikon say that you need 10.6.5+ for the latest firmware, although I don't see why.
    Thanks for that! I was looking for that manual, but for some reason, couldn't find it.
    I guess I'll have to contact Nikon and find out what the real story is. The camera was introduced in '08 or '09, so I'm wondering why you'd need software as recent as 10.6.5??
    Still very confusing.  :-?
    Why does it state that the camera is compatible with "10.4.11, 10.5.8..."? Does that mean that anything between 4.11 and 5.8 is incompatible???
    BTW, I tried downloading the 10.5.8 combo update recently and got an error message that the update was "corrupted" after it was all downloaded, so I was not able to install that.

  • When I try to backup my files from photoshop elements 12 the "calculating total media size" box will only get as far as 46% and then freeze, how can I make it go to 100%

    When I try to backup my files from photoshop elements 12 the "calculating total media size" box will only get as far as 46% and then freeze, how can I make it go to 100%

    hi barbara
    thank you for your response, i appreciate it.  there's definitely nothing wrong with the mouse or trackpad, both work fine in every other application....i can also easily change size dimensions in other programs on my computer so it doesn't seem to be that either.  it seems like there is something weird going on in the way that pse and my mac are interacting with each other, just wish i knew what it was.    thank you again, wish me luck!

  • HT204053 When I try to make a purchase at the Itunes store I will frequently get an error msg,that says unable to complete purchase, contact store support. why does this happen?

    From my Iphone 4S, I have trouble making purchases and will frequently get an error message that says, "Unaable to complete purchase at this time.  Contact Itunes Store Support to complete this purchase."  The strange thing is that it will sometimes go through without any problem but 1 out of 3 times this happens.  Any sugguestions?  My phone's completely updated.

    To Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • HT201209 Trying to redeem a free download for a song from KLove. When I get into my acct & try to redeem it, it just keeps bringing up the "sign-in" box. When I click the button on KLove's webpage to redeem it takes me to that page but does the same thing

    Trying to redeem a free download for a song from KLove. When I get into my acct & try to redeem it, it just keeps bringing up the "sign-in" box. When I click the button on KLove's webpage to redeem it takes me to that page but does the same thing

    Get the redeem code from the KLove page:
    http://www.klove.com/music/store.aspx
    ...and enter it into the Redeem Code box in the iTunes Store.
    You will have to sign in to your iTunes account.
    It worked fine here.  If that doesn't work for you, let us know what went wrong.

  • My 4th Gen Ipod touch will not get past the apple logo

    My 4th Gen Ipod touch will not get past the apple logo (unless the battery is dead, Then it tell me to charge it).  Once it gave me the connect to itunes screen.  I clicked restore in itunes but the ipod went back to the apple logo before the update download finished. I tried calling apple but my over the phone technical support just expired. PLEASE HELP! 

    This can be a corrupted software/firmware on your iPod touch. If the recovery mode you did was not forced, then try to force it into recovery mode. This is how:
    1. Force it to shut down (note: this sort of shut down should not be preformed unless you are in a situation like this because it is a hardware shutdown and will not attempt to unload software, save unsaved files, safely stop system processes, etc.) to do this, hold down the power/sleep button and home button for about 7 or 10 secs. Also I might be incorrect but I heard that you can just hold down the sleep and home button until the screen goes blank and then immediately let go.
    2. Have iTunes running. Hold down the home button and plug the USB cable that came with your iPod into it. Keep on holding on the home button until a picture of a USB cable going into the iTunes logo appears. You are now in a forced recovery mode. (In case your not so tech-savvy forced recovery is the same as a normal recovery mode that an iPod might do if it knows an update or restore failed.)
    3. iTunes should have shown a pop-up message about it found a iPod in recovery mode. Click OK, click your iPod from the sidebar and click restore. The iPod will show the apple logo for a while and iTunes will say "preparing iPod for restore" and then "waiting for iPod" this was the longest part of updates for me.
    4. iPod will reboot when restore is completed. When I update my iPod it one time showed the apple logo for one whole sync until it showed the slide to unlock screen, so do not worry. P.S if that does not work do a DFU mode restore ( I've been told DFU mode stands for device firmware update mode) I'm running out of room, so google it. Hope this helped ;)

  • When syncing with itunes, got error message saying had error and now ipad2 will not do anything other than showing the USB cable with arrow pointing to Itunes on screen.  have done the reset and restart, but still get same thing.

    when syncing with itunes, got error message saying had error and now ipad2 will not do anything other than showing the USB cable with arrow pointing to Itunes on screen.  have done the reset and restart, but still get same thing.  Ipad does not show up in itunes even though cable plugged in.  Have shut down and restarted Windows 7 computer.

    I had done all of that to no avail.  I did call Apple Tech Support and after he suggested I try a USB port in the rear of the Win 7 computer, things starting working again.  I had tried switching the USB port at the front of the machine but that had not helped.  Everything is good to go again.  thanks for  your reply

  • In logic Pro, when I open up an audio track and load an audio file, there is no sound. I will finally get a sound out of one of the audio tracks after opening at least 5 of them alternately. Is anyone familiar with this kind of bug? It's really frustratin

    In logic Pro, when I open up an audio track or software track and load an audio file/loop or software file loop, there is no sound. I will finally get a sound out of one of the audio or software tracks after opening at least 5 of them alternately. Is anyone familiar with this kind of bug? It's really frustrating as this takes much time to complete work.
    os x, Mac OS X (10.6)

    I'm not sure I follow your words Fuzzynormal. You've helped by offering the insight that my issue in Logic Pro 9 is not a bug but a feature. But fell short of enlightenment by being a judge of character and of how one should interact in this forum. You insinuate that I haven't tried to solve the issue on my own when in fact I have. These forums are always my last resort. You further suggest that I am complaining. This is not a complaint. It is a genuine issue that I cannot figure out. Then you think that Brazeca is holding my hand and being a nice guy. Brazeca is helping people like me who might not be as adept at using Logic Pro as probably you are.This community forum was established to raise questions, answers and dicussion to help Apple's customers better undertand their operating systems and related issues. You are doing a disservice by not contributing positively and by trying to make this forum what you want it to be. You may have all the time in the world to try figuring out stuff but we are not all like you. We all have different schedules and different levels of understanding. And that is what this forum is for - to help people move forward. If you can't contribute positively then keep silent. And by the way, you say to "read the words that are printed down to explain to you how that works" what words are you talking about? Why don't you be of some help instead of trying to own this forum. 

  • HT1766 I have an iphone 4.I upgraded it to 5.0.1 and so I have lost all the data from my iPhone,but i have a backup in my computer.How do I use the backup file ? i.e How will i get that backup file in my iPhone ?

    I have an iphone 4.I upgraded it to 5.0.1 and so I have lost all the data from my iPhone,but i have a backup in my computer.How do I use the backup file ? i.e How will i get that backup file in my iPhone ?

    Connect phone to computer.
    Select Restore.
    Tell iTunes which of the available backup files to use, let iTunes restore it.
    Also, try reading the User's Guide as it answers questions like this.

  • When will I get my 32GB Black Iphone4??????? Manager told me "I Don't Know"

    Been getting constant conflicting info from my local Lake Charles, LA store. Now the mobile manager has informed me that im not getting my 32GB Black iphone4 on release day and the best part of it is he told me he doesn't have a clue as to when I would get it. So I have no phone and no idea when im going to get it and all the manager wants to do is try and pass it off on Apple... Seems all they know how to do is point the finger at someone else but I remember who took my money and that's who is responsible.... I asked him if they was going to do anything for the customers that got screwed like this and again nothing.....  So No Phone, No Expected Date, No Goodwill Gesture, NO RESPECT....  Its clear Best Buy only cares about getting your money and nothing else!

    JBasco20 wrote:
    Been getting constant conflicting info from my local Lake Charles, LA store. Now the mobile manager has informed me that im not getting my 32GB Black iphone4 on release day and the best part of it is he told me he doesn't have a clue as to when I would get it. So I have no phone and no idea when im going to get it and all the manager wants to do is try and pass it off on Apple... Seems all they know how to do is point the finger at someone else but I remember who took my money and that's who is responsible.... I asked him if they was going to do anything for the customers that got screwed like this and again nothing.....  So No Phone, No Expected Date, No Goodwill Gesture, NO RESPECT....  Its clear Best Buy only cares about getting your money and nothing else!
    I don't work for Best Buy but I do work retail and we ARE at the mercy of the manufacturer. If they didn't get any in, they likely have no idea when they will be getting them or they would have told you. They aren't telling you something because they want to get under your skin, it's because they just don't know. They shouldn't have to "do anything" for the people who get "screwed" as you put it as it's not their fault and it's a pre-order.  My BB was nice enough to offer me a loaner phone until my 32gb comes in so I'm not without a phone (transferring numbers from Verizon) which I think is phenomenal. Best Buy would sell you the product if they had enough of them, trust me they aren't going to turn away sales.

  • Will I get my iPhone replaced for yellow tinting problem

    Will I get my iPhone 4S replaced for yellow tinting problem, it's hardly 6 months old phone and this problem is from day one. Screen is not whitish it's yellowish.

    If you think there is a problem with the screen, try making a reservation with a Genius.

  • Xperia arc S will not get Jelly Beans

    Closed toppic, multiple posts.
    As officially stated on Facebook, Xperia arc S and mini pro will not get Jelly beans update.
    http://www.xperiablog.net/2012/07/26/official-2011-sony-xperia-handsets-will-not-get-android-4-1-jel...
    As a conclusion of this, Jelly Beans will not be rolled out to any 2011 phone, as the arc S is the last and top model of the 2011 line.
    One of the best things in this facebook post is the proposal to buy a new phone...
    This proved again to be a lie of Sony, stating that they will support and update phones for at least 18 months.

    there are a lot of simillar posts like this, you can try to search the forum ,

Maybe you are looking for

  • How to delete old invitees from ical

    When creating a new appointment in ical, the invitee list autopopulates with old addresses - some of which ar every similar to new, and thus confuse... How does one get rid of these?  I have been to mail, window, previous recipients...and deleted...b

  • Can't view files in mini bridge

    Help - I've just had to reinstall photoshop due to a pc crash but now I've reinstalled I can 't view my files in mini bridge. Bridge itself is fine. Do I need to reset something? Thanks

  • Location registration with runtime..

    HI All, How can we register LOCATION with runtime.. I face this error. When I deploy mapping it will give error location not register with runtime?? HOw to solve this problem?? DJ

  • How to either hide or delete specific computer files Time Machine

    Hi i have a MBP late 2011 with 10.8.2 on it, and i use a time capsule to store a large amount of files that i use on both my mac and my windows 7 laptops. I am getting annoyed by all the unnessicary or junk files placed in all my stuff such as: .ini

  • When will Photoshop Elements 11 be released?

    My 30 day trial of PSE10 runs out in 2 days. I am very happy with it and intend to purchase. When does PSE11 come out? Is it better for me to wait? Regards, Russell Message title was edited by: Brett N