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: -
int *tspos, *tepos = NULL;
-
int tcc = 0;
-
.
-
.
-
.
-
// the following loop loops about 30000 times
-
// and saves the beggining and the ending position
-
// of some texts
-
loop() {
-
if((tspos=(int *)realloc(tspos,(tcc+1)*sizeof(int)))==NULL)
-
error("Memory error while saving temp text data!\n");
-
if((tepos=(int *)realloc(tepos,(tcc+1)*sizeof(int)))==NULL)
-
error("Memory error while saving temp text data2!\n");
-
tspos[tcc]=spos;
-
tepos[tcc]=epos;
-
tcc++;
-
}
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.
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
thank you
but the problem was here: - 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: - int *tspos, *tepos;
-
.
-
.
-
.
-
tspos=NULL;
-
tepos=NULL;
-
...
thanks.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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
|
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
|
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...
|
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
| |
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
|
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?
|
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
...
|
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...
|
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...
|
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: 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...
|
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: 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: 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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |