Skip to content
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

Variable allocations #7

Closed
wants to merge 5 commits into from

Conversation

gleono
Copy link

@gleono gleono commented Jul 12, 2018

This PR is intended for review purposes only. I will create a new PR after addressing feedback gathered here and ni#471 is merged into master.

Exposing 2 functions that will allow JS to allocate variables based on a Type declared in the .via code and of course deallocate the memory.

The workflow goes as follow:

var valueRef = vireo.eggShell.findValueRef(viName, path); // Look for a variable 
// valueRef contains a pointer to the type and the data for that variable
// allocateData only cares about the type.
var allocatedDataValueRef = vireo.eggShell.allocateData(valueRef); // This will allocate enough memory for that type
// Now any other functions to write and read can be used on the allocated space.
vireo.eggShell.writeJSON(allocatedDataValueRef, someValue);
vireo.eggShell.readJSON(allocatedDataValueRef);
// Once done with that data, e.g. after an event occurs, you can deallocate it.
vireo.eggShell.deallocateData(allocatedDataValueRef);

You can take a look to AllocateTypes.Test.js too.

@gleono gleono requested a review from rajsite as a code owner July 12, 2018 20:58
@gleono
Copy link
Author

gleono commented Jul 12, 2018

Can @segaljared, @cglzaguilar, @spathiwa please take a look to this?

}

if (dataRef == nullptr) {
return kEggShellResult_NullDataPointer;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we instead use kEggShellResult_InvalidDataPointer, that seems to be more generic and useful in other situations?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I like it better.


*dataRefLocation = nullptr;
Int32 topSize = typeRef->TopAQSize();
void* pData = THREAD_TADM()->Malloc(topSize);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember Paul recommending to not use Malloc in Vireo in general. Is there a function in tm (TypeManagerRef) that will allocate memory for us given a TypeRef?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test to ensure that we are not leaking memory?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, THREAD_TADM() is already using tm under the hood.

return kEggShellResult_NullDataPointer;
}

NIError error = typeRef->ClearData(dataRef);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a free call to release the dataRef pointer.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll add that. I couldn't find an easy way to enable memory leak checking from JS.

@gleono
Copy link
Author

gleono commented Jul 13, 2018

I'll create a new PR basing on master with the addressed feedback.

@gleono gleono closed this Jul 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants