Wiki Page Content

Differences between revisions 6 and 8 (spanning 2 versions)
Revision 6 as of 2011-05-17 18:13:55
Size: 1121
Editor: SheenaSmith
Comment: add SDL_GetError to RV
Revision 8 as of 2013-08-08 19:22:59
Size: 1413
Editor: RyanGordon
Comment: Oops
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
#pragma camelcase off
||<tablewidth="100%" style="color: #FF0000;" :> DRAFT||
#pragma disable-camelcase
Line 6: Line 5:
Use this function to create an SDL_RWops structure from memory of a certain size. Use this function to prepare a read-only memory buffer for use with RWops.
Line 12: Line 11:
SDL_RWops* SDL_RWFromMem(void* mem,
                        
int   size)
SDL_RWops* SDL_RWFromMem(void* mem, int size)
Line 17: Line 15:
||'''mem'''||,,a pointer to ,,^the memory location^||
||'''size'''||^the size of the memory location^||

<<Color2(green,Is '''mem''' an exception to the 'pointer rule'?)>>
||'''mem'''||a pointer to a buffer to feed an [[SDL_RWops]] stream||
||'''size'''||the buffer size, in bytes||
Line 23: Line 19:
A pointer to the SDL_RWops structure that is created or NULL on failure; call [[SDL_GetError]]() for more information. Returns a pointer to a new [[SDL_RWops]] structure, or NULL if it fails; call [[SDL_GetError]]() for more information.
Line 26: Line 22:
*
Line 29: Line 24:
SDL_RWops *rw;

rw = SDL_RWFromMem(bitmap, sizeof(bitmap));
SDL_SaveBMP_RW(screen, rw, 0);
SDL_RWops *rw = SDL_RWFromMem(bitmap, sizeof(bitmap));
SDL_SaveBMP_RW(screen, rw, 1);  /* closes RWOPS, leaves us memory buffer of data */
Line 34: Line 27:
*
Line 37: Line 29:
*<<BR>>If the memory is not writable, use [[SDL_RWFromConstMem]]() instead.<<BR>>* This function sets up an [[SDL_RWops]] struct based on a memory area of a certain size, for both read and write access.

This memory buffer is not copied by the RWops; the pointer you provide must remain valid until you close the stream. Closing the stream will not free the original buffer.

If you need to make sure the RWops never writes to the memory buffer, you should use [[SDL_RWFromConstMem]] with a read-only buffer of memory instead.
Line 40: Line 36:
 .[[SDL_RWFromConstMem]] ???
 .[[SDL_RWFromFile]] ???
 .[[SDL_RWFromFP]] ???
 .[[SDL_RWFromConstMem]]
 .[[SDL_RWclose]]
 .[[SDL_RWread]]
.[[SDL_RWwrite]]
 .[[SDL_RWseek]]
 .[[SDL_RWtell]]

SDL_RWFromMem

Use this function to prepare a read-only memory buffer for use with RWops.

Syntax

SDL_RWops* SDL_RWFromMem(void* mem, int size)

Function Parameters

mem

a pointer to a buffer to feed an SDL_RWops stream

size

the buffer size, in bytes

Return Value

Returns a pointer to a new SDL_RWops structure, or NULL if it fails; call SDL_GetError() for more information.

Code Examples

char bitmap[310000];
SDL_RWops *rw = SDL_RWFromMem(bitmap, sizeof(bitmap));
SDL_SaveBMP_RW(screen, rw, 1);  /* closes RWOPS, leaves us memory buffer of data */

Remarks

This function sets up an SDL_RWops struct based on a memory area of a certain size, for both read and write access.

This memory buffer is not copied by the RWops; the pointer you provide must remain valid until you close the stream. Closing the stream will not free the original buffer.

If you need to make sure the RWops never writes to the memory buffer, you should use SDL_RWFromConstMem with a read-only buffer of memory instead.


CategoryAPI, CategoryIO

None: SDL_RWFromMem (last edited 2015-06-20 20:00:06 by PhilippWiesemann)

(Page Info.)
Feedback
Please include your contact information if you'd like to receive a reply.
Submit