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

Segmentation Fault on stl::resize / stl::clear

I have segmentation fault when calling resize on an stl vector. I'm
unsure if I'm doing something horribly wrong or if the stl is being
dumb. The code breaks down like this:

-------------------------------------

class Device {
public:
Device() {
m_isBusy = false;
m_timeCh = -1.0;
m_timeService = 0.0;
} // Device

~Device() {}

private:
bool m_isBusy;

double m_timeCh;
double m_timeService;

};

class Queue {
public:
Queue() {
m_totalNumber = 0;
m_timeCh = 0.0;
} // Queue

/**** Destructor ****/
~Queue() { clear(); }

clear();
private:
list<TasktheQueue;
double m_timeCh;
int m_totalNumber;

};

void allocate() {
CPUS.resize(NUMBER_OF_CPUS); //type vector<device>
Disks.resize(NUMBER_OF_DISKS); //type vector<device>
diskQueues.resize(NUMBER_OF_DISKS); //type vector<Queue>
}

void clean() {
CPUS.clear();
Disks.clear();
diskQueues.clear();
Event_Queue.clear();
}

-----------------------
Essentially I repeatedly call allocate then clean. On about the 4th
time I call allocate I get the wonderful error message:

Segmentation fault (core dumped)

Any ideas?

Nov 6 '07 #1
2 3277
Event_Queue.clear() isnt actually there when the error appears so
ignore that.

Nov 6 '07 #2
Steve <ty******@gmail.comwrote in news:1194316256.702644.202250
@o3g2000hsb.googlegroups.com:
I have segmentation fault when calling resize on an stl vector. I'm
unsure if I'm doing something horribly wrong or if the stl is being
dumb. The code breaks down like this:
Given those two choices, I'd bet on you doing something horribly wrong
(sorry).

-------------------------------------

class Device {
public:
Device() {
m_isBusy = false;
m_timeCh = -1.0;
m_timeService = 0.0;
} // Device

~Device() {}

private:
bool m_isBusy;

double m_timeCh;
double m_timeService;

};

class Queue {
public:
Queue() {
m_totalNumber = 0;
m_timeCh = 0.0;
} // Queue

/**** Destructor ****/
~Queue() { clear(); }

clear();
private:
list<TasktheQueue;
double m_timeCh;
int m_totalNumber;

};

void allocate() {
CPUS.resize(NUMBER_OF_CPUS); //type vector<device>
Disks.resize(NUMBER_OF_DISKS); //type vector<device>
diskQueues.resize(NUMBER_OF_DISKS); //type vector<Queue>
}

void clean() {
CPUS.clear();
Disks.clear();
diskQueues.clear();
Event_Queue.clear();
}

-----------------------
Essentially I repeatedly call allocate then clean. On about the 4th
Does that mean you do _nothing_ between the allocate and clean?
time I call allocate I get the wonderful error message:

Segmentation fault (core dumped)
Not enough code. You haven't supplied the definition of Task (which is
probably where your real error is). As an example, replace Task with
int and see if you have the same problem. You also haven't shown what
Queue::clear() does.

Oh.. and nitpick: you should get into the habit of using initialization
lists in your constructors instead of assigning the initial values of
members.
Nov 6 '07 #3

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

Similar topics

9
by: fudmore | last post by:
Hello Everybody. I have a Segmentation fault problem. The code section at the bottom keeps throwing a Segmentation fault when it enters the IF block for the second time. const int...
8
by: Haro Panosyan | last post by:
Seems there is no reserve() function defined for STL map. If so, could someone please explain why? Same goes with resize(). Thanks, -haro
3
by: Suneeel | last post by:
Hi All, I'm having trouble with iterating through an STL map. Firstly, for an empty map, will map.begin() be equal to map.end()? If this is true, the program should not be entering the while...
2
by: tikcireviva | last post by:
Hi Guys, I am not sure what's wrong with my program. When I ran it under the GDB, it shows the following messages , which said that the issue is from stl_list.h. Does anyone know what's...
4
by: jois.de.vivre | last post by:
I'm having some unexpected behavior regarding clear() in the map container. I have the following code: /// --- begin code #include <map> #include <vector> #include <iostream> #include...
17
by: toton | last post by:
Hi, I am using a vector to reserve certain amount of memory, and reuse it for new set of data, to avoid reallocation of memory. so the call is something like vector<my_datav;///the temporary...
9
by: xman | last post by:
The codes below basically builds a binary tree. It runs well on Intel compiler. However, when I use gcc 4.2.0, the assignment to b.right causes segmentation fault. Tracing with valgrind reveals...
7
by: e2point | last post by:
hi, i got a program that is suppose to run 24x7x365. However after functioning for around 15 minutes, it crashes due to a segmentation fault. program is written in c++ and runs in RH Linux 4. When...
10
by: sagitalk | last post by:
Here is my code: #include <iostream> #include <vector> #include <fstream> #include <stdio.h> #include <string> #include <cstring> using namespace std;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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,...
0
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...
0
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,...

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.