CreateRamStream ?

BlitzMax Forums/BlitzMax Programming/CreateRamStream ?

Filax(Posted 2005) [#1]
Hi :)

I have try to understand the real use of RamStream but without example it's not very easy :)

Anybody have an example code to use Ram Stream ?

I have try :

Global MyRam:TRamStream
Global MyBank:TBank

MyRam=CreateRamStream(MyBank,BankSize(MyBank),True,True)
WriteLine MyRam,"CECI EST UN TEST"




SeekStream(MyRam,0)
Print ReadLine(MyRam)


Perturbatio(Posted 2005) [#2]
Strict

Global myRam : Byte Ptr = MemAlloc(128) 'allocate 128 bytes of memory to myRam

Global myStream : TRamStream = CreateRamStream(myRam, 128, True, True) 'Create a ram stream and link it to myRam

WriteLine(myStream, "test text") 'write the text
SeekStream(myStream, 0) 'reset the stream to the beginning
Print ReadLine(myStream)'read the text and print it

myStream = Null
MemFree(myRam, 128) 'clear the alloced memory

End



Filax(Posted 2005) [#3]
Many thanks Perturbatio :) your alway here to save me :)

But a last question ! it is possible to load media like image directly from ram stream ? And a little example ? :)

Thanks


Perturbatio(Posted 2005) [#4]
np :)

I've just updated it with comments to help out


Filax(Posted 2005) [#5]
Thanks ! if you have information about my previous post ! i'll take it :)


Perturbatio(Posted 2005) [#6]
incidentally, you can also just use TRamStream.Create() instead of CreateRamStream (it takes the same parameters). CreateRamStream simply calls the create method.

*EDIT*
I'll try and knock up something for loading an image now.


Filax(Posted 2005) [#7]
I love you :)


marksibly(Posted 2005) [#8]
Hi,

RamStream is pretty low level, and in there mainly to support 'incbin::'.

For streaming in/out of banks, use a BankStream instead. It will automatically grow the bank for you when writing and will ensure you don't read/write outside the limits of the bank.


Perturbatio(Posted 2005) [#9]
Mark, can you specify a RamStream or a BankStream as a URL?


Perturbatio(Posted 2005) [#10]
solved (a bit messy).


*EDIT*
The same thing using a TBankStream:



Filax(Posted 2005) [#11]
Many thanks Perturbatio ! i 'll explore your code !