Revision history for KeyPgDeallocate


Revision [20901]

Last edited on 2016-03-12 16:49:36 by fxm [Formatting]
Additions:



Revision [20185]

Edited on 2016-02-10 15:58:39 by DkLwikki [Update link format]
Additions:
[[KeyPgDeclare|declare]] [[KeyPgSub|sub]] **Deallocate** [[KeyPgCdecl|cdecl]] ( [[KeyPgByval|byval]] //pointer// [[KeyPgAs|as]] [[KeyPgAny|any]] [[KeyPgPtr|ptr]] )
This procedure frees memory that was previously allocated with ##[[KeyPgAllocate|Allocate]]##. ##//pointer//## must be a valid pointer. After the procedure returns, ##//pointer//## will be rendered invalid (pointing to an invalid memory address), and its use (dereferencing or calling **##Deallocate##** again) will result in undefined behavior.
'' new memory address
'' pointer is invalid
'' new memory address
In the program above, a reference pointer in a function is set to null after deallocating the memory it points to. An ##[[KeyPgAssert|ASSERT]]## macro is used to test if the original pointer is in fact null after the function call. This example implies the correct way to pass pointers to functions that deallocate the memory they point to is by reference.
- Not available in the //[[CompilerOptlang|-lang qb]]// dialect unless referenced with the alias ##**""__Deallocate""**##.
- ##[[KeyPgAllocate|Allocate]]##
- ##[[KeyPgReallocate|Reallocate]]##
Deletions:
[[KeyPgDeclare declare]] [[KeyPgSub sub]] **Deallocate** [[KeyPgCdecl cdecl]] ( [[KeyPgByval byval]] //pointer// [[KeyPgAs as]] [[KeyPgAny any]] [[KeyPgPtr ptr]] )
This procedure frees memory that was previously allocated with ##[[KeyPgAllocate Allocate]]##. ##//pointer//## must be a valid pointer. After the procedure returns, ##//pointer//## will be rendered invalid (pointing to an invalid memory address), and its use (dereferencing or calling **##Deallocate##** again) will result in undefined behavior.
'' new memory address
'' pointer is invalid
'' new memory address
In the program above, a reference pointer in a function is set to null after deallocating the memory it points to. An ##[[KeyPgAssert ASSERT]]## macro is used to test if the original pointer is in fact null after the function call. This example implies the correct way to pass pointers to functions that deallocate the memory they point to is by reference.
- Not available in the //[[CompilerOptlang -lang qb]]// dialect unless referenced with the alias ##**""__Deallocate""**##.
- ##[[KeyPgAllocate Allocate]]##
- ##[[KeyPgReallocate Reallocate]]##


Revision [17012]

Edited on 2014-03-09 16:10:42 by FxMwikki [Added some details]
Additions:
This procedure frees memory that was previously allocated with ##[[KeyPgAllocate Allocate]]##. ##//pointer//## must be a valid pointer. After the procedure returns, ##//pointer//## will be rendered invalid (pointing to an invalid memory address), and its use (dereferencing or calling **##Deallocate##** again) will result in undefined behavior.
Deletions:
This procedure frees memory that was previously allocated with ##[[KeyPgAllocate Allocate]]##. ##//pointer//## must be a valid pointer. After the procedure returns, ##//pointer//## will be rendered invalid (pointing to an invalid memory address), and its use will result in undefined behavior.


Revision [17010]

Edited on 2014-03-09 15:03:58 by FxMwikki [Added some details]
Additions:
Calling **##Deallocate##** on a null pointer induces no action.


Revision [15572]

Edited on 2011-12-18 23:31:23 by CountingPine [I don't think the first two points make sense...]
Additions:
Although in this case it is unnecessary since the function immediately exits afterwards, setting the pointer to null is a good habit to get into. If the function deallocated memory from a pointer that was passed in by reference, for instance, the pointer that was used in the function call will be rendered invalid, and it is up to the caller to either reassign the pointer or set it to null. Example 3 shows how to correctly handle this kind of situation, and the next example shows the effects of deallocating memory with multiple references.
Deletions:
Although in this case it is unnecessary - since 1. the pointer is not a reference to another pointer, 2. no other pointers point to the deallocated memory and 3. the function immediately exits afterward - setting the pointer to null is a good habit to get into. If the function deallocated memory from a pointer that was passed in by reference, for instance, the pointer that was used in the function call will be rendered invalid, and it is up to the caller to either reassign the pointer or set it to null. Example 3 shows how to correctly handle this kind of situation, and the next example shows the effects of deallocating memory with multiple references.


Revision [14595]

Edited on 2010-06-08 01:07:29 by CountingPine [##ASSERT##]
Additions:
In the program above, a reference pointer in a function is set to null after deallocating the memory it points to. An ##[[KeyPgAssert ASSERT]]## macro is used to test if the original pointer is in fact null after the function call. This example implies the correct way to pass pointers to functions that deallocate the memory they point to is by reference.
Deletions:
In the program above, a reference pointer in a function is set to null after deallocating the memory it points to. An [[KeyPgAssert ASSERT]] macro is used to test if the original pointer is in fact null after the function call. This example implies the correct way to pass pointers to functions that deallocate the memory they point to is by reference.


Revision [14594]

Edited on 2010-06-06 04:38:20 by DkLwikki [Missing cdecl]
Additions:
[[KeyPgDeclare declare]] [[KeyPgSub sub]] **Deallocate** [[KeyPgCdecl cdecl]] ( [[KeyPgByval byval]] //pointer// [[KeyPgAs as]] [[KeyPgAny any]] [[KeyPgPtr ptr]] )
Deletions:
[[KeyPgDeclare declare]] [[KeyPgSub sub]] **Deallocate** ( [[KeyPgByval byval]] //pointer// [[KeyPgAs as]] [[KeyPgAny any]] [[KeyPgPtr ptr]] )


Revision [14326]

Edited on 2009-08-29 21:53:15 by CountingPine [Remove CamelCase links in "New to FreeBASIC"]
Additions:
- New to ""FreeBASIC""
Deletions:
- New to FreeBASIC


Revision [14006]

Edited on 2008-12-02 09:51:08 by LaananFisher [Updated: byval]
Additions:
[[KeyPgDeclare declare]] [[KeyPgSub sub]] **Deallocate** ( [[KeyPgByval byval]] //pointer// [[KeyPgAs as]] [[KeyPgAny any]] [[KeyPgPtr ptr]] )
Deletions:
[[KeyPgDeclare declare]] [[KeyPgSub sub]] **Deallocate**( //pointer// [[KeyPgAs as]] [[KeyPgAny any]] [[KeyPgPtr ptr]] )


Revision [13458]

The oldest known version of this page was created on 2008-07-03 01:43:43 by DoS386 [Updated: byval]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode