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 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
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
"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
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
Frane Roje wrote: A *a = new A;
If you call new, you should call delete also.
delete a;
"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
"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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
|
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...
|
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.
|
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
....
...
..
|
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
| |
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
|
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...
|
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
|
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...
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |