4 Replies - 1416 Views - Last Post: 29 January 2010 - 11:30 PM Rate Topic: -----

#1 html_dns  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 29-December 08

Deep-Wise Copy An Unknown Struct

Posted 29 January 2010 - 10:03 PM

I'm writing an object wrapper for the SDL API written in C. The API provides allot of structures in which some of it's members are pointers to other structures. After coding a copy constructor for one on my classes I've come across a tricky situation, I need to copy the members of one structure to another but I'm faced with two problems. Firstly C++ by default does a bitwise copy, that is of one structure contains a pointer member the address is copied to the new structure instead of the content it is pointing to. Secondly, as I don't have access to the API structures directly I can't write a custom deep wise copy routine and forced to use C++'s method of copying. After searching some forums, I've come across BinaryFormatter and MemeortStream, haven't tested them out but it's on my to do list. If anyone has a different approach to this problem please share, thank you

Is This A Good Question/Topic? 0
  • +

Replies To: Deep-Wise Copy An Unknown Struct

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Deep-Wise Copy An Unknown Struct

Posted 29 January 2010 - 11:03 PM

Well... I am not sure I really understand the situation. If you have access to the structure definition than you can create a function to do a deep copy...

If you don't have access to the structure definition then... yea, your boned -- you can't do a deep copy without knowing the details of the implementation. pointers look like any other pieces of binary data in memory...

what does, "I don't have access to the API structures directly" mean?


BinaryFormatter is for serializing objects to a binary stream -- this kind of technique works on a VM type environment where a memory manager is keeping track of objects (and you have reflection) -- will not help with a C API.
Was This Post Helpful? 0
  • +
  • -

#3 html_dns  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 29-December 08

Re: Deep-Wise Copy An Unknown Struct

Posted 29 January 2010 - 11:12 PM

View PostNickDMax, on 29 Jan, 2010 - 10:03 PM, said:

Well... I am not sure I really understand the situation. If you have access to the structure definition than you can create a function to do a deep copy...

If you don't have access to the structure definition then... yea, your boned -- you can't do a deep copy without knowing the details of the implementation. pointers look like any other pieces of binary data in memory...

what does, "I don't have access to the API structures directly" mean?


BinaryFormatter is for serializing objects to a binary stream -- this kind of technique works on a VM type environment where a memory manager is keeping track of objects (and you have reflection) -- will not help with a C API.


Apologize for that, I was a little sketchy on the details, "I don't have access to the API structures directly" means I don't have access to the structure definition as it is hidden by SDL. So BinaryFormatter is out of the picture, can you think of anything else that may help
Was This Post Helpful? 0
  • +
  • -

#4 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Deep-Wise Copy An Unknown Struct

Posted 29 January 2010 - 11:26 PM

...see I think that is what is confusing me... SDL is open source... why not just download the source and find the definitions?

Basically if you don't have the definitions of the structures you can't do a deep copy, you NEED them. (I mean if you needed to you could probably use analysis tools to reverse engineer the structures...)
Was This Post Helpful? 0
  • +
  • -

#5 html_dns  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 29-December 08

Re: Deep-Wise Copy An Unknown Struct

Posted 29 January 2010 - 11:30 PM

View PostNickDMax, on 29 Jan, 2010 - 10:26 PM, said:

...see I think that is what is confusing me... SDL is open source... why not just download the source and find the definitions?

Basically if you don't have the definitions of the structures you can't do a deep copy, you NEED them. (I mean if you needed to you could probably use analysis tools to reverse engineer the structures...)

thank you for the advise, I'll do just that. If I come across a solution that doesn't require writing a deep-copy function I'll drop you a message
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1