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

Fine-grained memory operation with dcurl_entry #56

Closed
ajblane opened this issue Aug 7, 2018 · 4 comments
Closed

Fine-grained memory operation with dcurl_entry #56

ajblane opened this issue Aug 7, 2018 · 4 comments
Assignees

Comments

@ajblane
Copy link
Collaborator

ajblane commented Aug 7, 2018

For example of using dcurl API,

int8_t  *ret_trytes = null;
ret_trytes = dcurl_entry(...);
dcurl_destroy();

The ret_trytes is required to manually use free(), for example:

int8_t  *ret_trytes = null;
ret_trytes = dcurl_entry(...);
dcurl_destroy();
free(ret_trytes);

I suggest the dcurl_destroy() API can be added a argument to release ret_trytes, for example:

int8_t  *ret_trytes = null;
ret_trytes = dcurl_entry(...);
dcurl_destroy(ret_trytes);

This is because the sematic of dcurl_destroy is destroying usage resources. For using dcurl API, a developer maybe imagine ret_trytes can be released without using free() after using dcurl_destroy(). Would this suggestion is better?

@jserv
Copy link
Member

jserv commented Aug 7, 2018

The call sequence should be dcurl_init -> dcurl_entry -> dcurl_destroy where dcurl_init and dcurl_destroy are of the pair. I would suggest to add new function named dcurl_release which releases the resources allocated by dcurl_entry.

@furuame
Copy link
Member

furuame commented Aug 7, 2018

It seems that dcurl_release do the same thing as free, but more readable.
If ret_trytes passed as an argument, we can avoid this problem and the length of return tryte is known at static time.

int8_t ret_trytes[RETURN_TRYTES_LENGTH];
dcurl_entry(ret_trytes, ...);

@jserv jserv changed the title About memory allocation and release design for returned value of dcurl_entry() Fine-grained memory operation with dcurl_entry Aug 16, 2018
@jserv
Copy link
Member

jserv commented Aug 16, 2018

Related: #20
Cc. @chenwei-tw

@DLTcollab DLTcollab deleted a comment from furuame Aug 17, 2018
@ajblane
Copy link
Collaborator Author

ajblane commented Aug 19, 2018

The PR #59 achieves the goal. Close.

@ajblane ajblane closed this as completed Aug 19, 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

No branches or pull requests

3 participants