Hi everyone,
I have a problem with large dynamic memory allocating. this is my code (in briefness):
The runtime error occurs when program releases memory that is allocated to "Vec_".
This program gets 1GB of memory approximately, while the 32bits systems can use at most 4GB of memory.
if I reduce the value of "Adim" or "udim", program will get less memory, and there will be no error.
However I need to set these large values to both "Adim" and "udim".
My compliler is Borland C++ 5.02.
I will appreciate, if you help me to overcome this problem.
Thanks.
6 2701 Banfa 9,065
Expert Mod 8TB
If is not clear to me why you have chose to implement you own vectors ignoring the STL <vector> class, additionally you seem to be using a compiler that is 8at least 8 years old, you may wish to use a newer one.
Finally you have not said what error you are getting you have just alluded to some mysterious error without every mentioning it.
However I believe you problem is that you have not implemented any copy constructors or assignment operators. In this case the compiler creates them for you and it does a member to member copy and that means that at line 119 of your code all the vectors in your matrix end up sharing the same allocated memory buffer and so when they are deleted in the call to SetNVec at line 120 after the first vector in the array the destructor is trying to delete memory blocks that are no longer valid.
So I would guess you are getting invalid memory block exceptions during the delete.
Try running the same with Rational Purify to find if there are are any memory corruption......
That may help u to identify the issue.
raghu
I have made the code much simpler: -
class SVector_d
-
{
-
private:
-
double* V_;
-
public:
-
SVector_d() { V_ = 0; }; // Set V_ to NULL
-
~SVector_d() { delete[] V_; };
-
void SetSize(int N) { delete[] V_; V_ = new double[N]; }
-
};
-
-
int main() {
-
double* DPtr = new double[524281];
-
int SZ = 50000;
-
SVector_d* SVPtr = new SVector_d[SZ];
-
for(int i=0; i<SZ; i++) SVPtr[i].SetSize(1000);
-
delete[] SVPtr; // Error: Fault access violation...
-
delete[] DPtr;
-
return 0;
-
}
-
This code makes the same runtime error "Fault: access violation..." when the program frees memory allocated to "SVPtr" (at line 16).
What do i have to do to get out of this problem?
Declaring copy constuctor in class "SVector_d" does not help any more.
I reminde again that the program will run without any problem if i reduce dynamic memoy size. (Instance line 12 should be replaced by "double* DPtr = new double[500000];")
Thanks.
I don't get any access violation when I run this code nor on VC++ 2005 or Borland
C++ Builder 5. Try wrapping the allocation code inside try-catch block to see if any error happened during the allocation.
Banfa 9,065
Expert Mod 8TB
I agree with Savage, that 2nd set of code appears to be fine nothing wrong with it. It also runs for me in VS 2005 Express. It only failed when I set SZ high enough to cause the system to run out of virtual address space (About 2GB).
So my guess is that you are running into a limit of your platform (your platform being the compiler/OS combination you are using).
Also I was wrong wasn't I, your compiler is not 8 years old, that is C++ Builder 5, you compiler is 11 years old, and there appears to be anecdotal evidence that it is a 16bit compiler.
I seriously suggest you get something a little more modern, may be something released this century.
Your other options are
1. Try to work out what it is about your platform that is causing the error and find a work-around. Although I suspect it is hitting some hard-coded/hard-wired limit.
2. You could used memory mapped files, that is rather than trying to hold all your data in memory use a file to hold it and only load in part of it to operate on at a time. If you are able to use the WIN32 API then there are functions provided to enable you to do this fairly easily, look up MapViewOfFile on MSDN. Of course if your compiler is 16bit this may not be an option you may have to write the whole thing yourself.
You are right. I must get a new version of compiler. That is my answer. Thanks.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Peter Hickman |
last post by:
I have a program that requires x strings all of y length. x will be in the range
of 100-10000 whereas the strings will all be < 200 each.
This does not need to be grown once it has been created....
|
by: lwickland |
last post by:
Summary: System.Net.ScatterGatherBuffers.MemoryChuck allocates inordinately
large bytes when sending large post data.
The following application consumes inordinate quantities of memory. My code...
|
by: TheB |
last post by:
Ok, lets try this again.
I have a program which searches all disk drives for certain file types.
When it finds a file it writes a record to a Firebird DB. The program
normally is using 40 - 44...
|
by: EDom |
last post by:
Hi,
I have aspnet_wp.exe with increasing on every postback and not every revisit
to any page. Even if I clear session and close the browser it remains in the
memory. I have only one connection...
|
by: Martin Jørgensen |
last post by:
Hi,
I'm relatively new with C-programming and even though I've read about
pointers and arrays many times, it's a topic that is a little confusing
to me - at least at this moment:
----
1)...
|
by: coosa |
last post by:
Dear all,
Using the conio implementation i wanted to create a dynamic string,
whereby its size would be determined after each keyboard hit; in other
words, i don't want to ask the user to...
|
by: Francine.Neary |
last post by:
I'm experimenting with a program that manipulates a large matrix, i.e.
a 2-deep array. I started by just allocating this in one go, but later
it occurred to me that, as there are still some very...
|
by: marvinla |
last post by:
Hello!
I'm a beginner in C, and I'm having trouble with a pointer-to-pointer
reallocation.
This piece of code works well, but Valkyrie warns some parts (pointed
below), and is
breaking my real...
|
by: Jonathan Wilson |
last post by:
I am working on some software which has to deal with data that could be as
large as 500mb or so. Currently I am using new and delete to manage
this memory but I find it is not ideal and sometimes...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
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...
|
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...
| |