1

I'm using a C++ based framework which is based on rewriting rules. The individual rewriting rules are coded by developers like me. The parameters in the interface of the rewriting rules can be defined with any typed variables. What the framework appears to do is to apply a memcpy to all parameters when applying the rewriting rules.

Now I use instances of C++ objects (with somewhat complex inheritance from multiple abstract classes) as parameters of my rewriting rules. Not surprisingly, the memcpy is only partially successful and after the rewriting rule is applied, many members of my objects are messed up. In particular, pointer, map and vector members are messed up.

From what I read up I understand that memcpy is a fairly low-level copy mechanism. I was wondering if there was any way I could help fix the mess happening during memcpy? For example, if I defined copy constructors for all my classes - would memcpy be able to make use of them? Sorry in case this is a silly question.

(In case there is no way to make memcpy work for complex instances then I would conclude that the framework I have been working with is not suitable for passing objects)

0

1 Answer 1

1

std::memcpy:

Copies count bytes from the object pointed to by src to the object pointed to by dest. Both objects are reinterpreted as arrays of unsigned char.

memcpy copies bytes. It is unaware of what it actually copies.

... would memcpy be able to make use of them?

No.


PS

It sounds rather weird that a framework uses memcpy to copy C++ objects, because that is wrong except in certain special cases (cf. std::is_trivially_copyable). Or maybe you misunderstood something. There is too little context to give further advice

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot for your help! Yes, I find the use of memcpy also strange. There are some compiler warnings about the memcpy. It's a fairly old framework and might not have been intended for passing objects, but only for simple types. So I might be stretching the use of the framework too far in this case.
@daenin I am a bit confused by your distinction between "objects" and "simple types". There is no such distinction in C++ (see here en.cppreference.com/w/cpp/language/type). Also why is it such a secret what framework you are using ? ;) Also 20 years back it wasnt a good idea to use memcpy to copy objects btw
It's not a secret, it's just an extreme niche framework I would say. It can be found under "algorithmic botany" and uses an own little programming language called lpfg.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.