"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "doc/manual/cache/KeyPgReallocate.wakka" between
FreeBASIC-1.08.0-source.tar.xz and FreeBASIC-1.08.1-source.tar.xz

About: FreeBasic is a set of cross-platform development tools consisting of a compiler, GNU-based assembler, linker and archiver, and supporting runtime libraries, including a software-based graphics library.

KeyPgReallocate.wakka  (FreeBASIC-1.08.0-source.tar.xz):KeyPgReallocate.wakka  (FreeBASIC-1.08.1-source.tar.xz)
skipping to change at line 32 skipping to change at line 32
When using ##**Reallocate**##, the ##//result//## pointer must be saved t o prevent a potential memory leak, because the original ##//pointer//## may no l onger be valid after reallocation. The value of the new pointer should be check ed - if it is ##0##, the reallocation has failed - the original ##//pointer//## remains valid, and the amount of memory allocated to it has not changed. When using ##**Reallocate**##, the ##//result//## pointer must be saved t o prevent a potential memory leak, because the original ##//pointer//## may no l onger be valid after reallocation. The value of the new pointer should be check ed - if it is ##0##, the reallocation has failed - the original ##//pointer//## remains valid, and the amount of memory allocated to it has not changed.
Reallocated memory must be freed with ##[[KeyPgDeallocate|Deallocate]]## when no longer needed. Reallocated memory must be freed with ##[[KeyPgDeallocate|Deallocate]]## when no longer needed.
If ##//pointer//## is null (##0##), then ##""ReAllocate""## behaves ident ically to ##[[KeyPgAllocate|Allocate]]##. If ##//pointer//## is valid and ##//co unt//## is null (0), then ##""ReAllocate""## behaves similar to ##[[KeyPgDealloc ate|Deallocate]]## and a null (0) pointer is returned. If ##//pointer//## is null (##0##), then ##""ReAllocate""## behaves ident ically to ##[[KeyPgAllocate|Allocate]]##. If ##//pointer//## is valid and ##//co unt//## is null (0), then ##""ReAllocate""## behaves similar to ##[[KeyPgDealloc ate|Deallocate]]## and a null (0) pointer is returned.
If the memory has previously been deallocated by a call to ##[[KeyPgDeall ocate|Deallocate]]## or ##""ReAllocate""##, the behavior is undefined. If the memory has previously been deallocated by a call to ##[[KeyPgDeall ocate|Deallocate]]## or ##""ReAllocate""##, the behavior is undefined.
When manually allocating memory for ##[[KeyPgString|String]]## descriptor s (or ##[[KeyPgType|UDT]]##s that contain one), if ##//count//## is larger than the original size of the memory block, the new extra memory range must be explic itly cleared to zeroes before the first string use (for example, using ##[[KeyPg Clear|Clear]]##). Otherwise accessing the string will cause undefined results ( trying to write or read at a random place in memory, or trying to deallocate a r andom pointer). When manually allocating memory for ##[[KeyPgString|String]]## descriptor s (or ##[[KeyPgType|UDT]]##s that contain one), if ##//count//## is larger than the original size of the memory block, the new extra memory range must be explic itly cleared to zeroes before the first string use (for example, using ##[[KeyPg Clear|Clear]]##). Otherwise accessing the string will cause undefined results ( trying to write or read at a random place in memory, or trying to deallocate a r andom pointer).
This function is not part of the ""FreeBASIC"" runtime library, it is an
alias for the C runtime library's ##//realloc//##, so it's not guaranteed to be
thread safe in all platforms.
**NOTE**: Reallocating a pointer inside an object function, when that poi nter contains the parent object of the function, is undefined, and will likely r esult in horrible crashes. **NOTE**: Reallocating a pointer inside an object function, when that poi nter contains the parent object of the function, is undefined, and will likely r esult in horrible crashes.
{{fbdoc item="ex"}} {{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/memory/reallocate.bas"}}%%(freeba sic) {{fbdoc item="filename" value="examples/manual/memory/reallocate.bas"}}%% (freebasic)
Dim a as Integer Ptr, b as Integer Ptr, i As Integer Dim a as Integer Ptr, b as Integer Ptr, i As Integer
a = Allocate( 5 * SizeOf(Integer) ) ' Allocate memory for 5 integers a = Allocate( 5 * SizeOf(Integer) ) ' Allocate memory for 5 integers
If a = 0 Then Print "Error Allocating a": End If a = 0 Then Print "Error Allocating a": End
For i = 0 to 4 For i = 0 to 4
a[i] = (i + 1) * 2 ' Assign integers to the buffer a[i] = (i + 1) * 2 ' Assign integers to the buffer
Next i Next i
skipping to change at line 75 skipping to change at line 73
Print "Error Reallocating a" Print "Error Reallocating a"
For i = 0 to 4 ' Print the integers For i = 0 to 4 ' Print the integers
Print i, a[i] Print i, a[i]
Next i Next i
Print Print
end if end if
Deallocate a ' Clean up Deallocate a ' Clean up
%% %%
{{fbdoc item="lang"}} {{fbdoc item="lang"}}
- Not available in the //[[CompilerOptlang|-lang qb]]// dialect unless re ferenced with the alias ##**""__Reallocate""**##. - Not available in the //[[CompilerOptlang|-lang qb]]// dialect unless re ferenced with the alias ##**""__Reallocate""**##.
{{fbdoc item="diff"}} {{fbdoc item="diff"}}
- New to ""FreeBASIC"" - New to ""FreeBASIC""
{{fbdoc item="see"}} {{fbdoc item="see"}}
- ##[[KeyPgAllocate|Allocate]]## - ##[[KeyPgAllocate|Allocate]]##
- ##[[KeyPgCallocate|Callocate]]## - ##[[KeyPgCallocate|Callocate]]##
- ##[[KeyPgDeallocate|Deallocate]]## - ##[[KeyPgDeallocate|Deallocate]]##
 End of changes. 3 change blocks. 
7 lines changed or deleted 2 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)