473,396 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Huge memory problem

Pat
I am using VC++ 6.0 to develop my program.

class A
{
Object *obj
public:
A() { obj=new Object[10000] ; } ;

}

void main()
{
A *a=new A;
}

In my program, I need to allocate a huge memory for a Object obj (e.g. 10000
copies of object), which is inside the class A. However, when A's
constructor is being called. The program crash....

Could someone tell me how to solve this problem? Is it related to the C++
programming issue? BTW, my computer is 512MB RAM.

Pat
Jul 22 '05 #1
8 1585

"Pat" <Pa*@Pat.com> schreef in bericht news:40**********@rain.i-cable.com...
I am using VC++ 6.0 to develop my program.

class A
{
Object *obj
public:
A() { obj=new Object[10000] ; } ;
Last semicolon on this line is not needed.
}
Missing semicolon after the last bracket.
void main()
main() always returns int, even though VC++ 6.0 lets you get away with void
this is not legal C++.
{
A *a=new A;
}

In my program, I need to allocate a huge memory for a Object obj (e.g. 10000 copies of object), which is inside the class A. However, when A's
constructor is being called. The program crash....
In what way? Acces violation, out of memory ...etc?
Could someone tell me how to solve this problem?
You didn't provide a minimal yet complete (compilable) example that exhibits
the problem you are having. We don't know what 'Object' is and we don't know
the specifics of the crash you are seeing. Without that information, we can
only make wild guesses. Does the crash also happen when you allocate only 10
objects? If so the problem is probably not related to memory but with the
default constructor of Object.
Is it related to the C++ programming issue?
What is the 'C++ programming issue'?
BTW, my computer is 512MB RAM.


I'm very happy for you.

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl
Jul 22 '05 #2
Thi si my testing code:
#include <iostream>

#include <cstdlib>

using namespace std;

class Object {

int a;

int b;

int c;

};

class A {

Object* p;

public:

A() {p = new Object[10000000];}

~A() {delete p;}

};

int main()

{

A *a = new A;
system("pause");

return 0;

}

And it works just fine, and I have 192MB RAM,

The only error that I see in your code is that you have a

semicolon after the constructors code.

HTH
--
Frane Roje

Have a nice day

Remove (*dele*te) from email to reply
Jul 22 '05 #3

"Pat" <Pa*@Pat.com> wrote in message news:40**********@rain.i-cable.com...
I am using VC++ 6.0 to develop my program.

class A
{
Object *obj
public:
A() { obj=new Object[10000] ; } ;

}

void main()
{
A *a=new A;
}

In my program, I need to allocate a huge memory for a Object obj (e.g. 10000 copies of object), which is inside the class A. However, when A's
constructor is being called. The program crash....

Could someone tell me how to solve this problem? Is it related to the C++
programming issue? BTW, my computer is 512MB RAM.

Pat


There's not much wrong with your program from a C++ point of view. You have
some semi-colons in the wrong places and void main is illegal.

Without seeing the definition of Object it hard to say what the problem is.
However it is not that you don't have enough memory. The VC++ 6 compiler
does the wrong thing when it runs out of memory. What happens with VC++ 6 is
that new returns NULL when you don't have enough memory. So if you are
running out of memory then obj would be NULL, but that isn't happening, you
are getting a crash instead.

There's only one thing for you to do, post a complete compileable program
that crashes, its the only way to get this sort of problem fixed. Without a
complete program everyone is just guessing.

john
Jul 22 '05 #4
Pat
I try my program in g++, the problem is the same.
If the number of object is small (say 20). The program works well.
"Pat" <Pa*@Pat.com> 在郵件 news:40**********@rain.i-cable.com 中撰寫...
I am using VC++ 6.0 to develop my program.

class A
{
Object *obj
public:
A() { obj=new Object[10000] ; } ;

}

void main()
{
A *a=new A;
}

In my program, I need to allocate a huge memory for a Object obj (e.g. 10000 copies of object), which is inside the class A. However, when A's
constructor is being called. The program crash....

Could someone tell me how to solve this problem? Is it related to the C++
programming issue? BTW, my computer is 512MB RAM.

Pat

Jul 22 '05 #5
Frane Roje wrote:
A *a = new A;


If you call new, you should call delete also.

delete a;
Jul 22 '05 #6

"Pat" <Pa*@Pat.com> wrote in message news:40**********@rain.i-cable.com...
I try my program in g++, the problem is the same.
If the number of object is small (say 20). The program works well.


Great, but you still need to post a complete program. Otherwise everyone is
guessing what the problem is.

john
Jul 22 '05 #7

"Aggro" <sp**********@yahoo.com> wrote in message
news:ZS**************@read3.inet.fi...
Frane Roje wrote:
A *a = new A;
If you call new, you should call delete also.

delete a;


More to the point, if you call new[] you must call delete[].
~A() {delete[] p;}


john


Jul 22 '05 #8
Pat
Thanks everyone.

I try my best to debug my code.

Pat

"Pat" <Pa*@Pat.com> 在郵件 news:40**********@rain.i-cable.com 中撰寫...
I am using VC++ 6.0 to develop my program.

class A
{
Object *obj
public:
A() { obj=new Object[10000] ; } ;

}

void main()
{
A *a=new A;
}

In my program, I need to allocate a huge memory for a Object obj (e.g. 10000 copies of object), which is inside the class A. However, when A's
constructor is being called. The program crash....

Could someone tell me how to solve this problem? Is it related to the C++
programming issue? BTW, my computer is 512MB RAM.

Pat

Jul 22 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Anders S繪ndergaard | last post by:
Hi, I'm trying to process a large filesystem (+20 million files) and keep the directories along with summarized information about the files (sizes, modification times, newest file and the like)...
53
by: john67 | last post by:
The company I work for is about to embark on developing a commercial application that will cost us tens-of-millions to develop. When all is said and done it will have thousands of business...
5
by: Simon Adler | last post by:
Hello, I've got some Problems with a Programm. I use a Grid with Nodes. The Grid will be 64 * 64 Nodes huge. Each Node is a float. Some Algorithms ha've to copy the whole Grid, sometimes twice....
7
by: Vasil Buraliev | last post by:
Hallo. I started a solution in VS.NET with template for C# windwos application. The solution has several projects: -Artifacts -BusinessRules -Client -ErrorLog -Standardization .... ... ..
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an out of memory exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
5
by: Naamat | last post by:
Hello, I am the sample FPSEPublish (http://blog.baeke.info/blog/_archives/2005/3/3/393158.html) code to upload a document to Sharepoint (WSS). This works perfectly for samll documents. ...
12
by: Jeff Calico | last post by:
I have 2 XML data files that I want to extract data from simultaneously and transform with XSLT to generate a report. The first file is huge and when XSLT builds the DOM tree in memory, it runs...
13
by: fAnSKyer/C# newbie | last post by:
My system has 4GB memory and My program in C# is really memory consuming. and I noticed that when the memory I used is more than 2GB I will get an exception. How to solve this? thanks a lot
1
by: murataykut | last post by:
Hi, I'm writing image processing program on BCB. But, for huge amount of memory allocation BCB doesn't works properly. I want to allocate nearly 2 GB (total) dynamic arrays. For 1,5 GB there is no...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.