equivilent of java's float buffer

About Monkey 2 Forums Monkey 2 Programming Help equivilent of java's float buffer

This topic contains 5 replies, has 3 voices, and was last updated by  codifies 2 years, 5 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #4854

    codifies
    Participant

    I want to be able to build and maintain a chunk of “raw” memory that I could (easily) put float values into and then send a pointer to a c library

    I notice the GLES module uses ptr but I’m not too sure about the correct way to use this, for example, are “normal” mx2 float arrays guaranteed to be contiguous in memory…

    #4855

    nerobot
    Participant

    mx2 arrays are cpp arrays (because all mx-code translated to cpp before compiling), so they must be contiguous in memory, I think.

    #4857

    Mark Sibly
    Keymaster

    are “normal” mx2 float arrays guaranteed to be contiguous in memory…

    Yes, and arrays also have a ‘Data’ property that returns the raw memory used by the array in the form of a pointer, eg: an Int[] will return an Int Ptr.

    You can also use a DataBuffer and poke in values using PokeFloat etc, or even a Stack<Float> which also has a Data property only it returns the underlying array, eg:

    Also note that if the stack is modified, the underlying array may have to be resized (therefore changed) so you need to be a bit careful using stack like this.

    #4880

    codifies
    Participant

    thanks thats a great help I ended up with…

    I assume this is only safe as long as texture never leaves scope or is global 😉

    looks like its much closer to the “metal” than I thought which is nice…

    #4881

    Mark Sibly
    Keymaster

    Yep, that should work. There’s also Varptr:

    And of course there always good old ‘malloc’:

    looks like its much closer to the “metal” than I thought which is nice…

    You can indeed use it *very* close to the metal! The general idea is that if you write code without the use of pointers, the code should be 100% ‘safe’. Once you go into pointer land you’re on your own so you need to be careful, but at the same time mx2 doesn’t do anything to stop you doing this if you want/need to.

    #4882

    codifies
    Participant

    I managed to find varptr and Cast<type> by grep-ing …

    Its interesting that I like I can get to the “metal”, but equally love the fact that it uses actual human readable words in the code, I’ve been using Java for a while since the days of BlitzMax but its just getting too much ASCII soup and every shiny new fashionable language feature, sometimes you just want easy to read code, but that shouldn’t mean lack of power.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.