473,386 Members | 1,775 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,386 software developers and data experts.

Memory allocation error under Windows

Well, this is my first topic at this forum and I'm a newbie on C programming too.

I'm coding a little program and I've used some "dynamic arrays" on it. Compiling and running the program on Linux worked fine for me. But I was very curious to see how the program runs on Windows, so I decided to test it. Compilation was fine too, but when I run the program, I get a memorry allocation error.

Here's the code:

Expand|Select|Wrap|Line Numbers
  1. int *tspos, *tepos = NULL;
  2. int tcc = 0;
  3. .
  4. .
  5. .
  6. // the following loop loops about 30000 times
  7. // and saves the beggining and the ending position
  8. // of some texts
  9. loop() {
  10.     if((tspos=(int *)realloc(tspos,(tcc+1)*sizeof(int)))==NULL)
  11.         error("Memory error while saving temp text data!\n");
  12.     if((tepos=(int *)realloc(tepos,(tcc+1)*sizeof(int)))==NULL)
  13.         error("Memory error while saving temp text data2!\n");
  14.     tspos[tcc]=spos;
  15.     tepos[tcc]=epos;
  16.     tcc++;
  17. }

That is the part. I compiled it and when I run it I get the message "Memory error while saving temp text data!"

On Linux I was using the gcc compiler. On Windows, I'm using Dev-C++ 4.9.9.2 with Mingw/GCC 3.4.2.

Ss I said, it is compiled on Windows, but I get the memory error when try to run.

I think that it's because of the differences between Windows/Linux memory allocation and need to say that my program uses "a lot of memory" (more especificaly, something about 25MiB).

So, why did it occurs? It's because of the "malloc/realloc" inside a big loop?

Thanks for the answers.
Feb 11 '09 #1
2 3284
JosAH
11,448 Expert 8TB
Maybe you do actually run out of memory when running on MS Windows; one little thing: why don't you initialize tspos to NULL when you start your loop?

kind regards,

Jos
Feb 11 '09 #2
thank you

but the problem was here:

Expand|Select|Wrap|Line Numbers
  1. int *tspos, *tepos = NULL;
according to another answer that i received, "tepos has a value of NULL, tspos has an undefined value. GCC might handle that more gracefully by default than Dev-C++" (ref: http://www.gidforums.com/showthread....0127#post80127).

so, all I have to do is:

Expand|Select|Wrap|Line Numbers
  1. int *tspos, *tepos;
  2. .
  3. .
  4. .
  5. tspos=NULL;
  6. tepos=NULL;
  7. ...
thanks.
Feb 11 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Mike P | last post by:
I know everything about reference counting and making sure you don't have large objects lying around. I have also profiled my app with multiple tools. I know about the fact GC collects memory but...
4
by: PaulR | last post by:
Hi, We have a Server running SLES 8 and 3GB memory, with 1 DB2 instance and 2 active Databases. General info... DB2level = "DB2 v8.1.0.72", "s040914", "MI00086", and FixPak "7" uname -a =...
2
by: mghale | last post by:
Greetings, I have moved a database from the DB2 Windows Platform (Dev) to our production AIX Server and am experiencing an issue: The AIX platform is 5.3 and DB2 version 8.1 pixpack 9a...
3
by: Florin | last post by:
Hi all, I have a problem related to memory grow on a server application which is basically stateless (I have some static info loaded). The client accesses this server using remoting and it has...
30
by: MAG1301 | last post by:
I've detected memory leaks in our huge .NET 1.1 C# application but couldn't localize them directly. So I've reduced the code to the following console application: using System; using System.IO;...
66
by: Johan Tibell | last post by:
I've written a piece of code that uses sockets a lot (I know that sockets aren't portable C, this is not a question about sockets per se). Much of my code ended up looking like this: if...
81
by: Peter Olcott | last post by:
It looks like System::Collections::Generic.List throws and OUT_OF_MEMORY exception whenever memory allocated exceeds 256 MB. I have 1024 MB on my system so I am not even out of physical RAM, much...
1
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was...
1
by: vectorizor | last post by:
Hello all, I am writing a Photoshop plug-in on Windows, and I am having trouble with allocating memory. Essentially, the code performs a very complex operation on the image, so 9 buffer planes...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
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 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.