Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7747571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:33:48+00:00 2026-06-01T10:33:48+00:00

When trying to save the database using boost serialization, I encounter the segfault that

  • 0

When trying to save the database using boost serialization, I encounter the segfault that I could not resolve. Would you please help? Any suggestion is greately appreciated.
I’ve pinned down the statement below as the culprit but not sure of how to resolve it

oa << *this;

My code section is below:

template<class Archive>
void nDB::serialize(Archive &ar, const unsigned int version) {
    ar & _LAYERS;
    ar & _MACROS;
    ar & _MODULES;
    ar & _INSTS;
}

void nDB::save_db(string filename) {
    std::ofstream ofs(filename.c_str(), std::ios::out | std::ios::binary);
    //assert(ofs.good());
    boost::archive::binary_oarchive oa(ofs);
    oa << *this;
    ofs.close();
}

Hi,
I was able to pin point the issue to a circular reference in my database. The code are below:

    template<class Archive>
    void pin::serialize(Archive &ar, const unsigned int version) {
    ar & pin_Port;
    ar & pin_Layer;
    }

and

    template<class Archive>
    void port::serialize(Archive & ar, const unsigned int version){
    ar & port_Name;
    ar & port_Use;
    ar & port_Dir;
    ar & port_PINS;
    }

Hi below are my class definition

    class pin {
    public:
    port*       pin_Port;
    layer*      pin_Layer;
    // rect*       pin_shape;

    pin();
    ~pin();

    void         set_port(port*);
    void         set_layer(layer*);
    string       get_name();
    port*        get_port();
    layer*       get_layer();
    string       get_layer_name();
    double       get_layer_width();
    private:
    friend class boost::serialization::access;
    template<class Archive>
    void serialize(Archive & ar, const unsigned int version);
    };
    class port {
    public:
    string     port_Name;
    char       port_Use;
    char       port_Dir;
    pin_vector port_PINS;
    port();
    ~port();

    void         set_name(string);
    void         set_use(int);
    void         set_dir(int);
    string       get_name(void);
    string       get_use(void);
    string       get_dir(void);
    void         add_pin(pin*);
    pin_vector   get_all_pins(void);

    private:
    friend class boost::serialization::access;
    template<class Archive>
    void serialize(Archive & ar, const unsigned int version);
    };
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:33:49+00:00Added an answer on June 1, 2026 at 10:33 am

    I suspect the culprit is ofs.close();. The binary_oarchive object needs to go out of scope before the underlying stream is closed, because the binary_oarchive object tries to write remaining data and flush the stream in its destructor.

    Standard streams are flushed and closed automatically when they go out of scope, so the line is completely unnecessary (and in this case, harmful). Remove it and you should be good to go.

    (Unrelated, but _LAYERS, _MACROS, etc. are terrible names, and in fact are illegal in user code. Get rid of either the leading underscore or the capital letters, preferably both.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to save an entity to my database using this code: public void
I am currently trying to access the data that was just inserted using: if($this->User->save($this->data))
I am trying to update as well as save data to my database using
Using CakePHP 1.3 I'm trying to save some data to a MySQL database. The
I'm trying to save an object that has 2 similar lists using a hbm.xml
I'm trying to save data from HTML table to database using jquery to call
I am trying to save changes to my database trough a rake task. In
I am trying to save data to a database on a button push, but
The idea: I'm just trying to save some Chinese characters to a MySQL database.
Hi I am trying to use NSUserDefaults to save some default values in database.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.