log in | register | forums
Show:
Go:
Forums
Username:

Password:

User accounts
Register new account
Forgot password
Forum stats
List of members
Search the forums

Advanced search
Recent discussions
- Elsear brings super-fast Networking to Risc PC/A7000/A7000+ (News:)
- Latest hardware upgrade from RISCOSbits (News:)
- Announcing the TIB 2024 Advent Calendar (News:1)
- Code GCC produces that makes you cry #12684 (Prog:39)
- RISCOSbits releases a new laptop solution (News:)
- Rougol November 2024 meeting on monday (News:)
- Drag'n'Drop 14i1 edition reviewed (News:)
- WROCC November 2024 talk o...ay - Andrew Rawnsley (ROD) (News:2)
- October 2024 News Summary (News:3)
- RISC OS London Show Report 2024 (News:1)
Latest postings RSS Feeds
RSS 2.0 | 1.0 | 0.9
Atom 0.3
Misc RDF | CDF
 
View on Mastodon
@www.iconbar.com@rss-parrot.net
Site Search
 
Article archives
Acorn Arcade forums: Programming: Corrupt heap
 
  Corrupt heap
  (13:57 28/4/2001)
  monkeyson (14:15 29/4/2001)
    Phlamethrower (10:23 30/4/2001)
 
Phlamethrower Message #4763, posted at 13:57, 28/4/2001
Unregistered user When this program is compiled and run with GCC, it complains of a corrupt heap:

#include <stdio.h>
#include <stdlib.h>

class foo
{
public:
int blah;
foo() {printf("foo at %d\n",(int) this);}
~foo() {printf("foo killed at %d\n",(int) this);}
};

void main()
{
poo *t;
t = new foo[10];
delete t;
}

Basically what I want to know is whether this is a bug in GCC, a limit of C++, or that I've done something wrong somewhere.

  ^[ Log in to reply ]
 
monkeyson Message #4764, posted at 14:15, 29/4/2001, in reply to message #4763
Unregistered user s/poo/foo

I got a seg fault from Linux. Platform independence!

You need to alter the delete so that you're deleting an array of foos, not an individual foo.

foo *t;
t = new foo();
delete t;

foo *t;
t = new foo[10];
delete [ ] t;

  ^[ Log in to reply ]
 
Phlamethrower Message #4765, posted at 10:23, 30/4/2001, in reply to message #4764
Unregistered user Ah, right. I think I tried delete t[], but not delete []t.
  ^[ Log in to reply ]
 

Acorn Arcade forums: Programming: Corrupt heap