473,732 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Many differerent problems with seg faults.

Hi, everybody. I am new here.

I have encountered these many problems for the last couple of days. I
have Linux Fedora Core 3(Gnu G++ 3.4.2), Linux Fedora Core 2 (Gnu G++
3.3.3), Red Hat 9 (Gnu G++ 3.2.2, this is dual processors).

I have the same set of programs that I wrote and when I ran on the
three machines, which have different amount of memories, processors'
speeds, and settings. I got three different seg faults at different
places in the programs. Basically each machine would give me a seg
fault at different points in the program codes.

I don't think my program use up all memory that would create seg fault,
and I don't think the errors stem from the faults that I tried to
access memory that wasn't allocated by my program. The seg faults were
all because of my program try to allocate memory.

Another thing is I am using gsl library, which is written in C, in my
C++ program and this library has its own functions to allocate memory
but at the lower system level calls it uses C malloc calls. I get seg
faults at:

0x081096a8 in _int_malloc ()
#1 0x08108e7b in malloc ()
#2 0x0807962b in gsl_block_alloc (n=6) at init_source.c:3 9
#3 0x08070a68 in gsl_vector_allo c (n=6) at init_source.c:4 0
------------------------------------------------------------
0x081185e7 in _int_malloc ()
#1 0x08119c41 in malloc ()
#2 0x08075222 in gsl_vector_allo c (n=2) at init_source.c:3 2
#3 0x080752cd in gsl_vector_call oc (n=2) at init_source.c:6 4
-----------------------------------------------------

I just can not understand why I also get error relating to seg fault or
double free memory for codes like this:

void calculate21Iter (char* ctipParams, char* eamParams, int numMatrix)
{
double* results = NULL;
try{
results = new double[NITER];
}
catch(bad_alloc )
{
cerr<<"Failed to get memory for results in utility. Exit\n";
exit(1);
}
int count = 0;
for(int i = 0; i < numMatrix; i++)
{
for(int j = 0; j < NITER; j++)
{
results[count] = calculateEtot(c tipParams, count, eamParams);
count++;
}
writeTDatFile(i , results);
}
cout<<"done 21 iter\n";
//delete [] results;
cout<<"just delete results\n";
}

If i do not comment out delete [] results; I would get a double free of
memory errors( I don't have the exact descriptions but basically it say
I free some memory twice). If you looked at the function call
writeTDatFile(i , results); you see i passed results there, but in that
function I do not delete the memory. So could it be that when that
function reach the end of execution, the results in that function is
out of scope and then got free automatically and then in this function,
I free it one more time.

I also have a corrupted memory errors that basically happened to data
members of a class.
double *counts;
Names *sysNames;
int types;

The counts and names will be allocated with new double/Names[types]
after I read types from the file.

Somehow, I ran the program and then types would become some huge
negatives number, I f I found a way to fix types, then counts would be
corrupted. If i fix counts, then sysNames would be corrupted. It is
just a cycle of corrupted error among the three.
The bad thing is I ran a total of 63 iteration over these variables and
each time the values supposed to not change but at the same iterations
for different variables, I would get memory corrupted. (54. types, fix
types, 34. counts, fix counts, 45. sysNames, fix sysNames, then 54.
types......).

All these just drive me crazy.

Could somebody here give me some lights into these problems?

Thank you so very much.

Jul 23 '05 #1
4 1725
st********@hotm ail.com wrote in news:1108432247 .709765.250770
@c13g2000cwb.go oglegroups.com:
Hi, everybody. I am new here.

I have encountered these many problems for the last couple of days. I
have Linux Fedora Core 3(Gnu G++ 3.4.2), Linux Fedora Core 2 (Gnu G++
3.3.3), Red Hat 9 (Gnu G++ 3.2.2, this is dual processors).

I have the same set of programs that I wrote and when I ran on the
three machines, which have different amount of memories, processors'
speeds, and settings. I got three different seg faults at different
places in the programs. Basically each machine would give me a seg
fault at different points in the program codes.
Symptoms _strongly_ suggest that you've messed up your memory somewhere.
I don't think my program use up all memory that would create seg fault,
and I don't think the errors stem from the faults that I tried to
access memory that wasn't allocated by my program. The seg faults were
all because of my program try to allocate memory.
Nope, you've most likely written somewhere in memory where you're not
supposed to.
Another thing is I am using gsl library, which is written in C, in my
C++ program and this library has its own functions to allocate memory
but at the lower system level calls it uses C malloc calls. I get seg
faults at:

0x081096a8 in _int_malloc ()
#1 0x08108e7b in malloc ()
#2 0x0807962b in gsl_block_alloc (n=6) at init_source.c:3 9
#3 0x08070a68 in gsl_vector_allo c (n=6) at init_source.c:4 0
------------------------------------------------------------
0x081185e7 in _int_malloc ()
#1 0x08119c41 in malloc ()
#2 0x08075222 in gsl_vector_allo c (n=2) at init_source.c:3 2
#3 0x080752cd in gsl_vector_call oc (n=2) at init_source.c:6 4
-----------------------------------------------------

I just can not understand why I also get error relating to seg fault or
double free memory for codes like this:

void calculate21Iter (char* ctipParams, char* eamParams, int numMatrix)
{
double* results = NULL;
try{
results = new double[NITER];
}
catch(bad_alloc )
{
cerr<<"Failed to get memory for results in utility. Exit\n";
exit(1);
}
int count = 0;
for(int i = 0; i < numMatrix; i++)
{
for(int j = 0; j < NITER; j++)
{
results[count] = calculateEtot(c tipParams, count, eamParams);
count++;
}
writeTDatFile(i , results);
}
cout<<"done 21 iter\n";
//delete [] results;
cout<<"just delete results\n";
}
If numMatrix > 1, this function will write beyond the bounds of the array
named 'results'. I leave it as an exercise to the reader to see why
(hint: what is being used to index into the results array).
If i do not comment out delete [] results; I would get a double free of
memory errors( I don't have the exact descriptions but basically it say
I free some memory twice). If you looked at the function call
writeTDatFile(i , results); you see i passed results there, but in that
function I do not delete the memory. So could it be that when that
function reach the end of execution, the results in that function is
out of scope and then got free automatically and then in this function,
I free it one more time.

I also have a corrupted memory errors that basically happened to data
members of a class.
double *counts;
Names *sysNames;
int types;

The counts and names will be allocated with new double/Names[types]
after I read types from the file.

Somehow, I ran the program and then types would become some huge
negatives number, I f I found a way to fix types, then counts would be
corrupted. If i fix counts, then sysNames would be corrupted. It is
just a cycle of corrupted error among the three.
The bad thing is I ran a total of 63 iteration over these variables and
each time the values supposed to not change but at the same iterations
for different variables, I would get memory corrupted. (54. types, fix
types, 34. counts, fix counts, 45. sysNames, fix sysNames, then 54.
types......).
Yep, you've most likely written past the end of an array.

All these just drive me crazy.

Could somebody here give me some lights into these problems?


Yep, you're writing beyond the bounds of arrays. Probably ones which you
have dynamically allocated.

Come to think of it, in the function you posted above, what's the purpose
of dynamically allocating the array? Why not just declare it as a normal
local variable?
Jul 23 '05 #2
Thanks Andre for the tips. I couldn't believe my eyes when I looket at
the count++ withour reseting it to zero.

Yup, that is the result of pulling around 55 / hours /week at work and
some more hours at home.

I need to relax and then reexamine my codes.

Thanks Andre.

Jul 23 '05 #3
stephen7 wrote:
Thanks Andre for the tips. I couldn't believe my eyes when I looket at
the count++ withour reseting it to zero.

Yup, that is the result of pulling around 55 / hours /week at work and
some more hours at home.

I need to relax and then reexamine my codes.

I think you would benefit the most if you programmed with the more safe
and high level facilities of C++, without sacrificing efficiency,
instead of writing "assembly" with C++.
Consider your code modified:
#include <iostream>
#include <vector>
#include <cstdlib>
#include <new>
#include <string>

void calculate21Iter (const std::string &ctipParams,
const std::string &eamParams,
const int numMatrix) try
{
using namespace std;

vector<double> results(NITER);

int count = 0;

for(int i = 0; i < numMatrix; ++i)
{
for(vector<doub le>::size_type j = 0; j < results.size(); ++j)
{
//Can't figure out what this is supposed to do
}

writeTDatFile(i , results);
}
cout<<"done 21 iter\n";
}
catch(std::bad_ alloc)
{
using namespace std;

cerr<<"Failed to get memory for results in utility. Exit\n";
exit(EXIT_FAILU RE);
}


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #4
Ioannis Vranos wrote:

stephen7 wrote:
Thanks Andre for the tips. I couldn't believe my eyes when I looket at
the count++ withour reseting it to zero.

Yup, that is the result of pulling around 55 / hours /week at work and
some more hours at home.

I need to relax and then reexamine my codes.


I think you would benefit the most if you programmed with the more safe
and high level facilities of C++, without sacrificing efficiency,
instead of writing "assembly" with C++.
Consider your code modified:
#include <iostream>
#include <vector>
#include <cstdlib>
#include <new>
#include <string>

void calculate21Iter (const std::string &ctipParams,
const std::string &eamParams,
const int numMatrix) try
{
using namespace std;

vector<double> results(NITER);

int count = 0;

for(int i = 0; i < numMatrix; ++i)
{
for(vector<doub le>::size_type j = 0; j < results.size(); ++j)
{
//Can't figure out what this is supposed to do
}

writeTDatFile(i , results);
}
cout<<"done 21 iter\n";
}
catch(std::bad_ alloc)
{
using namespace std;

cerr<<"Failed to get memory for results in utility. Exit\n";
exit(EXIT_FAILU RE);
}

And catch(std::bad_ alloc) is not needed here for general applications.
In general applications, one can place one catch(std::bad_ alloc) for
main() only.


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2743
by: benben | last post by:
Is there a standard guidline to avoid or minimize page faults when manipulating data collections in C++? ben
2
2640
by: Dave Kirby | last post by:
I am working on a network management program written in python that has multiple threads (typically 20+) spawning subprocesses which are used to communicate with other systems on the network. This runs fine for a while, but eventually slows down to a crawl. Running sar shows that when it is running slowly there is an exceptionally large number of minor page faults - there are continuously 14000 faults/sec, with a variation of about...
27
5681
by: Sune | last post by:
Hi! Pre-requisites: ------------------- 1) Consider I'm about to write a quite large program. Say 500 K lines. 2) Part of this code will consist of 50 structs with, say, no more than at most 1K bytes of data. 3) These structs are to be used by all of the other 500K lines in various places.
1
6557
by: tbatwork828 | last post by:
I've PerfMon-ed our application for several days now and it consistently averages 2000 Page Faults/sec, and accumulates on average about 4 mill page faults during 35 mins. During the same monitoring time of 35 mins, there is never any sustained occurence of hard page faults -as a matter of fact, almost on avg 98+ % of the entire time the app is experiencing soft page faults. The processor rarely ever gets over 70-80% for a sustained...
4
3804
by: tbatwork828 | last post by:
Related to my other post on Graphics.FillRectangle and a lot of page faults caused by this call... We determine that when Control.DoubleBuffer=true to avoid the flicker effect, Graphics.FillRectangle causes a lot of soft page faults - order of 700/sec and more... When Control.DoubleBuffer=false, we have no page faults at all - 0/sec. Has anyone seen this behavior and how did they resolve it...? What are our options...? Does...
17
1945
by: Lee Harr | last post by:
I understand how to create a property like this: class RC(object): def _set_pwm(self, v): self._pwm01 = v % 256 def _get_pwm(self): return self._pwm01 pwm01 = property(_get_pwm, _set_pwm)
3
1568
by: Acolyte | last post by:
Alright, here's what I'm working on now. It's supposed to go through an inputted list of words, pick out actual words and create a numbered list of them, then, where it finds a number in the list, go back in the list from that number, replace it with a word, augment the list accordingly and continue. Anyways, here's what I have: #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main () {
3
1829
by: scotp | last post by:
Does anyone know what would cause excessive page faults running the js function below? The most common browser used is IE 6. The page has records that include text & checkbox inputs. Each record also has a hidden input named "questions", whose value is an id that is used in the name of inputs to be disabled. The number of page faults increases dramatically as records increase. I know it is the for loop that is taking the extra time,...
4
2169
by: none | last post by:
I have an ASP.NET application, hosted on two web servers. I am looking for advice on what should be an acceptable level of page faults on these production servers. If the acceptable level is zero, then where should I begin reducing page faults in code? What should I look for in code to reduce page faults? Having to reduce page faults is something I have not had been tasked with before, so I am not sure what is acceptable and where to...
0
8944
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
8773
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
9445
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
9306
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
9234
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
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6733
isladogs
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...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3259
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 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.