Page 4 of 4 FirstFirst ... 234
Results 31 to 35 of 35

Thread: O2 - some basic questions

  1. #31
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171
    OK, thanks Charles, that explains it. Make a note for the help-file

    John, of course I got some plan and a goal in the end. It might take two years or more but I have no hurry - not with that nor with putting that shotgun into my mouth and pull the trigger
    The way to get there needs a few steps and one of the most fundamentals is, that I need some very flexible, extremely dynamic, nodeable memory-management for the data i expect. The problem would be that I know how it will work but I have no clue how to manage this fast enough since these calls to calculate some pointer-position or index might occur twice or more often per codeline. So it has to go lightning speed to be of use. One key to get speed is to call functions with as few as even possible parameters byval and also few local variables - except statics of course.

    I see no methods in oxygen-docs to alloc something and I don't know how to get the Heap_Size from tB to oxygen without passing it in each call. That would be no option.

    Maybe you got some hint for me where the size of some allocated heap gets stored? Can oxygen identify some heap-memory that was allocated by tB somehow?
    Does oxygen probably have own methods to allocate memory in any kind of blocks (but no ordinary strings) that would be accessable from tB then?
    I'm definetely not interested if I would need any 3rd party software therefor.
    I think there are missing some Forum-sections as beta-testing and support

  2. #32
    The oxygen way of getting heap memory:

    sys p=getmemory 1000 x sizeof double
    double d at p
    d(900)=4.2

    Releasing heap memory:

    freememory p

    The memory space is always initialised with null bytes.


    You can also work with any ThinBasic variable space by passing a member of any array variable byref. This will then be treated as the base member of a dynamic array on the Oxygen side. But you will still need to pass the number of elements or memory size you intend processing. If this is constant over meny calls, then you can use a separate function to set it.
    Last edited by Charles Pegge; 11-08-2013 at 10:16.

  3. #33
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171
    Isn't there a limit of 511/512 for memory? I thought I read something like this.
    Also important to know: how can I retrieve the size of some allocated block of O2-memory when I just have it's pointer?

    How to test if p is a valid pointer?
    Last edited by ReneMiner; 11-08-2013 at 10:17.
    I think there are missing some Forum-sections as beta-testing and support

  4. #34
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171
    So in tB
    if Heap_Size(myHeap)  then
     ' its for sure a pointer to some allocated heap
    ' and it's size is known
    endif
    
    and almost all of my functions need this size to calculate with. If I would have to pass it in each call would be very cumbersome. To be fast I can not afford to keep track on each memory-blocks size and this size is essential to all element-, node- and organizer-functions I wrote.
    I think it would be much better to have it ALL done by O2 - the calculating of positions as well as the storing to memory and it probably would not make much sense to use tB-heap-functionalities and calculate in O2.
    I would appreciate if GetMemory(1000) would instantly allocate 1004 bytes and return pointer to byte 5 as starting position. The other four bytes in front could tell the size. But probably for compatibility-reasons it's not possible to change the existing GetMemory-function and I would have to add one dword in front myself and write some wrappers to Get/FreeMemory...On the other hand: this size has been stored somewhere anyway - how else would FreeMemory know how much to deallocate? So a SizeOf( Memory p ) should be possible somehow...

    And another question: is there something like SetAt(myVar, myAddress) in tB, to place some virtual overlay to another position or 0 to "neutralize" it?
    Or would I need to use somewhat like Redim myVar At myAddress ?

    Once again: I've read in oxyygen-helpfile about memory:

    Remarks

    Currently up to 1024 getmemory allocations are supported - thereafter the oldest get recycled. But if the strings are freed with freememory in the reverse order in which they were created, (like a stack) then this limitation does not apply.
    is that still the case?
    Last edited by ReneMiner; 12-08-2013 at 14:57.
    I think there are missing some Forum-sections as beta-testing and support

  5. #35
    In Oxygen, heap memory allocation is done via olestrings/bstrings. Thus the length is always to be found in a long value immediately preceding the string bytes.

    The theoretical upper limit in length for a olestring is 2 gig (2^31-1)

    These snippets do the same thing:

    sys m = getmemory 0x8000
    double d at m
    d[100]=1.23
    print d[100]
    ...
    print *(m-4) 'length
    freememory m



    bstring m = nuls 0x8000
    double d at m
    d[100]=1.23
    print d[100]
    ...
    print len m
    frees m



    thinBasic uses bstrings as its native string type, and a returned string from an oxygen function is always a bstring.

    I hope this helps. The string / heapspace duality is very useful in practice.

Page 4 of 4 FirstFirst ... 234

Similar Threads

  1. Replies: 0
    Last Post: 14-07-2013, 17:27
  2. Questions About Focus
    By gungadout in forum thinBasic General
    Replies: 2
    Last Post: 12-11-2010, 03:44
  3. three questions
    By christianssen in forum thinBasic General
    Replies: 6
    Last Post: 10-03-2010, 11:12
  4. A few more questions..
    By oldpapa49 in forum thinBasic General
    Replies: 12
    Last Post: 21-03-2009, 21:45
  5. DT questions
    By Dave in forum DT (Date module)
    Replies: 9
    Last Post: 16-04-2008, 09:48

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •