Code Monkey home page Code Monkey logo

Comments (4)

tetzank avatar tetzank commented on August 22, 2024

Is this function just a fancy malloc, or is it doing anything else besides allocating?

You can always pretend that the function signature looks different for the current context, see:

// call realloc with increased size
using realloc_type = T *(*)(T*,size_t); // fix realloc void* type issue, coat has no cast
auto vr_newstart = coat::FunctionCall(self.cc, (realloc_type)realloc, "realloc", vr_start, vr_size << 1);

Here, both void* in realloc()'s signature are casted to T*, T being the element type of the vector in this case. So, in COAT, we use T*, but it calls the function which uses void*. You can probably use something very similar.

from coat.

EduardoGRocha avatar EduardoGRocha commented on August 22, 2024

That wouldn't work if you want to write multiple datatypes to the same Buffer. Suppose you have a table of form (uiint64_t, uint32_t, uint8_t).

Then if you want to materialize tuples of this table (to sort for example), I would expect something like the following:

// Buffer store returns a uint8_t*
coat::Ptr<CC, coat::Value<CC, uint8_t>> store_address = coat::FunctionCall(fn, buffer.store_tuple, "tuple_store",16);

// Registers with values to be stored
register0 = coat::Value<CC, uint64_t>(fn, val0);
register1 = coat::Value<CC, uint32_t>(fn, val1);
register2 = coat::Value<CC, uint8_t>(fn, val2);

auto ptr0 = store_address.cast<CC, coat::Value<CC, uint64_t>>();
*ptr0 = register0;
store_address +=8
auto ptr1 = store_address.cast<CC, coat::Value<CC, uint32_t>>();
*ptr1 = register1;
store_address +=4
auto ptr2 = store_address.cast<CC, coat::Value<CC, uint8_t>>();
*ptr2 = register2;

from coat.

tetzank avatar tetzank commented on August 22, 2024

Well, then we need a cast function. It was on my todo list anyway. I pushed a change, see the example:

coat/examples/cast.cpp

Lines 36 to 42 in 94cc783

auto first = coat::cast<uint64_t*>(buf);
*first = 0xCAFEBABE'CAFED00Dul;
buf += sizeof(uint64_t);
auto second = coat::cast<uint32_t*>(buf);
*second = 0xDEADC0DEu;
buf += sizeof(uint32_t);
*buf = 42;

from coat.

EduardoGRocha avatar EduardoGRocha commented on August 22, 2024

I just tested it and seems to work. Thanks a lot!
How can one contribute to the project?

from coat.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.