Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

optimisation for getting a std::string from a ERL_NIF_TERM #5

Open
silviucpp opened this issue Oct 29, 2016 · 0 comments
Open

optimisation for getting a std::string from a ERL_NIF_TERM #5

silviucpp opened this issue Oct 29, 2016 · 0 comments

Comments

@silviucpp
Copy link

silviucpp commented Oct 29, 2016

Hello I was wonder why instead using enif_get_string and enif_get_list_length why you are not doing something like :

// std::string
inline int get(ErlNifEnv *env, ERL_NIF_TERM term, std::string &var)
{
    ErlNifBinary bin;
    int ret

    if(enif_is_binary(env, term))
        ret = enif_inspect_binary(env, term, &bin);
    else
        ret = enif_inspect_iolist_as_binary(env, term, &bin);

    if(!ret)
        return 0;

    var = std::string((const char*)bin.data, bin.size);
    return ret;
}

Kind regards,
Silviu

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant