ivan.velho

Forum Replies Created

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • in reply to: Memory Pool – Manual memory management #4271

    ivan.velho
    Participant

    There is no problem:

    Namespace std.graphics

    #rem monkeydoc Pixmaps allow you to store and manipulate rectangular blocks of pixel data.

    A pixmap contains a block of memory used to store a rectangular array of pixels.

    #end
    Class Pixmap

    #rem monkeydoc @hidden
    #end
    Field OnDiscarded:Void()

    #rem monkeydoc Creates a new pixmap.

    @param width The width of the pixmap in pixels.

    @param height The height of the pixmap in pixels.

    @param format The pixmap format.

    @param data A pointer to the pixmap data.

    @param pitch The pitch of the data.

    #end
    Method New( width:Int,height:Int,format:PixelFormat=PixelFormat.RGBA32 )

    Local depth:=PixelFormatDepth( format )
    Local pitch:=width*depth
    Local data:=Cast<UByte Ptr>( libc.malloc( pitch*height ) )

    _width=width
    _height=height
    _format=format
    _depth=depth
    _data=data
    _pitch=pitch
    OnDiscarded=Lambda()
    libc.free( data )
    End
    End

     

    Pixmap calls libc.free(data)

    I believe it is not in garbage collector at all.

    I believe Mark used the approach from libgdx (LWJGL)and allocate and delete resources out of garbage collector, through native method.

    in reply to: Memory Pool – Manual memory management #4270

    ivan.velho
    Participant

    I think I could use another approach to the problem.

    I can use  SDL/libc to allocate SDL pixmaps.

    These are the major resources , I must study this solution . I believe monkey2 is based on SDL and the low level SDL/libc were provided to give a low level control.

    I think I must study the integration and figure out how to do this .

    Thanks guys for the help.

    in reply to: Memory Pool – Manual memory management #4260

    ivan.velho
    Participant

    The limitation of this method is the pool must contain only objects of the same class.
    You cannot do up cast as down cast.

    in reply to: Memory Pool – Manual memory management #4259

    ivan.velho
    Participant

    My problem is free memory in time the destruction method is called, same problem every garbage collector has.
    But if you want to be faster than a constructor method, I suggest you to create a pool of objects with a recycle method, this method must do the same as a constructor but it will do on an allocated object.
    This is the reason you can’t be faster with any other strategy.

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