-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C++ move semantics, copying, destructors, memory management #13
Comments
Main issue that arises from this difference - I need to figure out a way how to "mend together" nim and C++ object ownership/memory-management semantics. Nim (sadly) does not have precise tools for handling objects, like "function requires rvalue", "cannot copy", "cannot default-construct" (nim-lang/RFCs#252) and the best nim counterpart for some of these cases would be just "API by convention", which would just lead users into codegen bugs. |
Running with block :tmp:
var c
c = CxxContainer[NimObject](value: NimObject(field: 2))
var c1_cursor = c
`=destroy`(c) |
Partially related nim-lang/RFCs#432 - if would be nice to have some form of "requires move" etc. annotations |
Two possible ways of implementing - proc newImportAux*() {.importc: "//", header: "<new>".} =
discard
proc newType(arg1, arg2...) ref Type =
new(result)
newImportAux()
{.emit: "new ((void*)result) Type(`arg1`, `arg2`);.} or
|
In these two example nim and C++ code produce completely different results - nim calls destructor only once, does not invoke neither copy nor move.
The text was updated successfully, but these errors were encountered: