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 8778189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:28:06+00:00 2026-06-13T19:28:06+00:00

Possible Duplicate: Copying one structure to another I have a struct defined as struct

  • 0

Possible Duplicate:
Copying one structure to another

I have a struct defined as

struct CKTcircuit 
{ 
    more than a 100 pointers and objects of different types  of structure.
    this structure has around 500 lines just declaring variables & pointers.
}

Now I have a object of this type instantiated.

And I have to create a copy this same type.

Any solutions how do I do this?

P.S.: I need to do this because I need to launch another thread doing computations and modifying the CKTcircuit object.

  • 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-13T19:28:07+00:00Added an answer on June 13, 2026 at 7:28 pm

    1) The hard way:

    For a deep copy you’ll need to traverse the entire structure and recreate it one node at a time. But make sure you use the pointers from the copy and not from the original data structure.

    here’s a simplified pseudo code example.

    node traverse_cp(node, checked_list){
       // makes sure you don't traverse back edges twice. or you'll loop.
       if ( checked_list[node] ) return checked_list[node];
    
    
       new_node = copy_node_data(node);
       new_node.left = traverse_cp(node->left, check_list + node);
       new_node.right = traverse_cp(node->right, check_list + node);   
       return node_node;
    }
    

    2) Short cuts

    A) Contiguous memory
    If you could guarantee that your memory was contiguously allocated (malloc once and then hand out the memory on your own), then you can just memcpy the whole block and then search for addresses in that address space and just modify them. But, that’s not very robust.

    B) Array of struct
    Use a preallocated array of your structures and indices instead of pointers. But that won’t work for a heterogenous data structure. This is basically a rewrite of your program.

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

Sidebar

Related Questions

Possible Duplicate: Copying one structure to another struct node { int n; struct classifier
Possible Duplicate: Mercurial: copying ONE file and its history to another repository I have
Possible Duplicate: Copying files from one directory to another in Java How can I
Possible Duplicate: Java: recommended solution for deep cloning/copying an instance I have an object
Possible Duplicate: Copying MySQL Database to another machine I am doing a java project
Possible Duplicate: Disable copying data from webpage Most content in a webpage could be
Possible Duplicate: deep copy NSMutableArray in Objective-C ? I have two arrays of length
Possible Duplicate: Circular definition in C typedef struct{ node *next; node *last; } doubleLink;
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: What is the most efficient way to clone a JavaScript object? Copying

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.