473,779 Members | 2,047 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Memory allocation error under Windows

2 New Member
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 3317
JosAH
11,448 Recognized Expert MVP
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
ravishi
2 New Member
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
2354
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 not necessary give it back to the OS. It seems that .NET win app will only return memory to the OS when the OS is asking for it. But!!! When the OS is asking for it is usually too late, tons of swapping and slow performance.
4
6771
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 = Linux galahad 2.4.19-64GB-SMP #1 SMP /etc/sysctl.conf kernel.shmmax=268435456
2
9671
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 (8.1.1.89) There hardware is Power5 8 procs, 4 online and 8 GB of memory. When I create the the database with the 8 bufferpools that existed in DB2 Windows, then try to connect to the database, I receive an error
3
3759
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 worked for about 2 years without problems. The problem I have encountered lately is that the memory on server side started to grow and not to be released. I have checked first new functionalities but after isolating these on separate server, the...
30
4703
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; namespace MemLeak { class MemLeak
66
3643
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 (function(socket, args) == -1) { perror("function"); exit(EXIT_FAILURE); } I feel that the ifs destroy the readability of my code. Would it be
81
4576
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 less virtual memory. Are other people experiencing this same problem?
1
7978
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 compiled and run without any erros but the second program has a run time error when the function return from allocate and the ptr become NULL. How to fixed this? Second Program: /* Best Method to allocate memory for 2D Array because it's ...
1
4014
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 are required as scratch memory. The problem occurs when the image that a user tries to process is big, say 10 mega pixels or more. A Photoshop error pops up saying "Could not complete the command because of a program error". The error occurs in...
0
9632
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9471
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
10302
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10136
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
10071
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
9925
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...
0
5372
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...
1
4036
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3631
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.