473,785 Members | 2,969 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1603

"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.merke rk(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**********@y ahoo.com> wrote in message
news:ZS******** ******@read3.in et.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
1578
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) in an instance hierarchy in memory. I read the information from a Berkeley Database. I'm keeping it in a Left-Child-Right-Sibling instance structure, that I operate on recursively.
53
3558
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 objects/classes, some of which will have hundreds-of-thousands of instances stored in a DB. Our clients will probably have somewhere between 50-200 users working on the app during the day, possibly in mutiple offices, and then a large number of batch...
5
1482
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. If this happens, the code crashes. I've to choose a smaller Grid Spacing from 32 * 32 Grid Nodes, or less. Who can I use more Memory? I use vector, just because I read that indexed access is fast.
7
2083
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
3807
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 one day): \\FFDS24\ASP.NET Applications(_LM_W3SVC_1_Root_ATV2004)\Errors During Execution: 7 \\FFDS24\ASP.NET Apps v1.1.4322(_LM_W3SVC_1_Root_ATV2004)\Compilations
5
26298
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. Problem: When I attempt to upload a huge document (300Megabayte) on a PC with 3.6Gig RAM I am getting a OutOfMemoryException when the program attempts to read the
12
5364
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 out of space. I only need a few branches of elements from the original XML, so I am seeking a recomended way of building a DOM for XSLT of only the elements that I need. I'm writing a Java application that invokes Xalan, and reading up on SAX...
13
5459
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
2244
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 problem. But when this size incresing it gives bad allocation error. In that computer there is 2 GB physical memory and I use WinXP (and I add /3GB to boot.ini). For testing I wrote an Visual C++ code in another PC which has 1 GB phyisical RAM. In...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10148
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.