By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,050 Members | 1,171 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,050 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
Event_Queue.clear() isnt actually there when the error appears so
ignore that.

Nov 6 '07 #2

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.