Revision history for KeyPgAllocate


Revision [22404]

Last edited on 2018-08-29 06:50:51 by fxm ['New' -> 'New Expression']
Additions:
As the initial value of newly allocated memory is unspecified, **Allocate** must not be directly used with ##[[KeyPgString|String]]## or ##[[KeyPgType|UDT]]## containing string, because the string descriptor being not cleared (containing random data), that may induce corrupted string or more (trying to write to a random place in memory or trying to deallocate a random pointer). It is mandatory in that case (with string or UDT containing string) to use ##[[KeyPgCallocate|Callocate]]## (clearing memory), or ##[[KeyPgOpNew|New Expression]]## (calling constructor) in case of **UDT**, or at worst after **Allocate** to explicitly clear the descriptor (setting to 0) before the first string use.
Deletions:
As the initial value of newly allocated memory is unspecified, **Allocate** must not be directly used with ##[[KeyPgString|String]]## or ##[[KeyPgType|UDT]]## containing string, because the string descriptor being not cleared (containing random data), that may induce corrupted string or more (trying to write to a random place in memory or trying to deallocate a random pointer). It is mandatory in that case (with string or UDT containing string) to use ##[[KeyPgCallocate|Callocate]]## (clearing memory), or ##[[KeyPgOpNew|New]]## (calling constructor) in case of **UDT**, or at worst after **Allocate** to explicitly clear the descriptor (setting to 0) before the first string use.


Revision [21554]

Edited on 2016-08-15 13:10:15 by DkLwikki [Revert previous change, it was correct]
Additions:
<<::c::
Deletions:
>>::c::


Revision [21553]

Edited on 2016-08-15 13:09:11 by DkLwikki [Use >> instead of << to close block]
Additions:
>>::c::
Deletions:
<<::c::


Revision [20822]

Edited on 2016-03-12 14:59:15 by fxm [Formatting]
Additions:
<<## 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377##
<<::c::
Deletions:
## 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377##


Revision [20818]

Edited on 2016-03-12 14:49:41 by fxm [Formatting]
Additions:




## 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377##
Deletions:
<<## 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377##>>
::c::


Revision [20045]

Edited on 2016-02-10 15:54:27 by DkLwikki [Update link format]
Additions:
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Allocate** [[KeyPgCdecl|cdecl]] ( [[KeyPgByval|byval]] //count// [[KeyPgAs|as]] [[KeyPgUinteger|uinteger]] ) [[KeyPgAs|as]] [[KeyPgAny|any]] [[KeyPgPtr|ptr]]
As the initial value of newly allocated memory is unspecified, **Allocate** must not be directly used with ##[[KeyPgString|String]]## or ##[[KeyPgType|UDT]]## containing string, because the string descriptor being not cleared (containing random data), that may induce corrupted string or more (trying to write to a random place in memory or trying to deallocate a random pointer). It is mandatory in that case (with string or UDT containing string) to use ##[[KeyPgCallocate|Callocate]]## (clearing memory), or ##[[KeyPgOpNew|New]]## (calling constructor) in case of **UDT**, or at worst after **Allocate** to explicitly clear the descriptor (setting to 0) before the first string use.
The pointer that is returned is an [[KeyPgAny|any]] [[KeyPgPtr|ptr]] and points to the start of the allocated memory. This pointer is guaranteed to be unique, even if ##//count//## is zero.
Allocated memory must be deallocated, or returned back to the free store, with ##[[KeyPgDeallocate|Deallocate]]## when no longer needed.
'' old address is lost and that memory is leaked
- Not available in the //[[CompilerOptlang|-lang qb]]// dialect unless referenced with the alias ##**""__Allocate""**##
- ##[[KeyPgCallocate|Callocate]]##
- ##[[KeyPgReallocate|Reallocate]]##
- ##[[KeyPgDeallocate|Deallocate]]##
Deletions:
[[KeyPgDeclare declare]] [[KeyPgFunction function]] **Allocate** [[KeyPgCdecl cdecl]] ( [[KeyPgByval byval]] //count// [[KeyPgAs as]] [[KeyPgUinteger uinteger]] ) [[KeyPgAs as]] [[KeyPgAny any]] [[KeyPgPtr ptr]]
As the initial value of newly allocated memory is unspecified, **Allocate** must not be directly used with ##[[KeyPgString String]]## or ##[[KeyPgType UDT]]## containing string, because the string descriptor being not cleared (containing random data), that may induce corrupted string or more (trying to write to a random place in memory or trying to deallocate a random pointer). It is mandatory in that case (with string or UDT containing string) to use ##[[KeyPgCallocate Callocate]]## (clearing memory), or ##[[KeyPgOpNew New]]## (calling constructor) in case of **UDT**, or at worst after **Allocate** to explicitly clear the descriptor (setting to 0) before the first string use.
The pointer that is returned is an [[KeyPgAny any]] [[KeyPgPtr ptr]] and points to the start of the allocated memory. This pointer is guaranteed to be unique, even if ##//count//## is zero.
Allocated memory must be deallocated, or returned back to the free store, with ##[[KeyPgDeallocate Deallocate]]## when no longer needed.
'' old address is lost and that memory is leaked
- Not available in the //[[CompilerOptlang -lang qb]]// dialect unless referenced with the alias ##**""__Allocate""**##
- ##[[KeyPgCallocate Callocate]]##
- ##[[KeyPgReallocate Reallocate]]##
- ##[[KeyPgDeallocate Deallocate]]##


Revision [17480]

Edited on 2015-04-01 10:56:12 by DkLwikki [integer => uinteger]
Additions:
[[KeyPgDeclare declare]] [[KeyPgFunction function]] **Allocate** [[KeyPgCdecl cdecl]] ( [[KeyPgByval byval]] //count// [[KeyPgAs as]] [[KeyPgUinteger uinteger]] ) [[KeyPgAs as]] [[KeyPgAny any]] [[KeyPgPtr ptr]]
Deletions:
[[KeyPgDeclare declare]] [[KeyPgFunction function]] **Allocate** [[KeyPgCdecl cdecl]] ( [[KeyPgByval byval]] //count// [[KeyPgAs as]] [[KeyPgInteger integer]] ) [[KeyPgAs as]] [[KeyPgAny any]] [[KeyPgPtr ptr]]


Revision [15199]

Edited on 2011-08-17 14:08:42 by FxMwikki [integer => uinteger]
Additions:
As the initial value of newly allocated memory is unspecified, **Allocate** must not be directly used with ##[[KeyPgString String]]## or ##[[KeyPgType UDT]]## containing string, because the string descriptor being not cleared (containing random data), that may induce corrupted string or more (trying to write to a random place in memory or trying to deallocate a random pointer). It is mandatory in that case (with string or UDT containing string) to use ##[[KeyPgCallocate Callocate]]## (clearing memory), or ##[[KeyPgOpNew New]]## (calling constructor) in case of **UDT**, or at worst after **Allocate** to explicitly clear the descriptor (setting to 0) before the first string use.
Deletions:
As the initial value of newly allocated memory is unspecified, **Allocate** must not be directly used with ##[[KeyPgString String]]## or ##[[KeyPgType UDT]]## containing string, because the string descriptor being not cleared, that may induce corrupted string or more (crash). It is mandatory in that case (with string or UDT containing string) to use ##[[KeyPgCallocate Callocate]]## (clearing memory), or ##[[KeyPgOpNew New]]## (calling constructor) in case of **UDT**, or at worst after **Allocate** to explicitly clear the descriptor (setting to 0) before the first string use.


Revision [15191]

Edited on 2011-08-17 07:19:19 by FxMwikki [integer => uinteger]
Additions:
Attempts to allocate, or reserve, ##//count//## number of bytes from the free store (heap). The newly allocated memory is not initialized.
Deletions:
Attempts to allocate, or reserve, ##//count//## number of bytes from the free store (heap).


Revision [15185]

Edited on 2011-08-17 06:05:31 by FxMwikki [integer => uinteger]
Additions:
Attempts to allocate, or reserve, ##//count//## number of bytes from the free store (heap).
As the initial value of newly allocated memory is unspecified, **Allocate** must not be directly used with ##[[KeyPgString String]]## or ##[[KeyPgType UDT]]## containing string, because the string descriptor being not cleared, that may induce corrupted string or more (crash). It is mandatory in that case (with string or UDT containing string) to use ##[[KeyPgCallocate Callocate]]## (clearing memory), or ##[[KeyPgOpNew New]]## (calling constructor) in case of **UDT**, or at worst after **Allocate** to explicitly clear the descriptor (setting to 0) before the first string use.
The pointer that is returned is an [[KeyPgAny any]] [[KeyPgPtr ptr]] and points to the start of the allocated memory. This pointer is guaranteed to be unique, even if ##//count//## is zero.
Deletions:
Attempts to allocate, or reserve, ##//count//## number of bytes from the free store (heap). The initial value of newly allocated memory is unspecified. The pointer that is returned is an [[KeyPgAny any]] [[KeyPgPtr ptr]] and points to the start of the allocated memory. This pointer is guaranteed to be unique, even if ##//count//## is zero.


Revision [14592]

Edited on 2010-06-06 04:36:46 by DkLwikki [Missing cdecl]
Additions:
[[KeyPgDeclare declare]] [[KeyPgFunction function]] **Allocate** [[KeyPgCdecl cdecl]] ( [[KeyPgByval byval]] //count// [[KeyPgAs as]] [[KeyPgInteger integer]] ) [[KeyPgAs as]] [[KeyPgAny any]] [[KeyPgPtr ptr]]
Deletions:
[[KeyPgDeclare declare]] [[KeyPgFunction function]] **Allocate** ( [[KeyPgByval byval]] //count// [[KeyPgAs as]] [[KeyPgInteger integer]] ) [[KeyPgAs as]] [[KeyPgAny any]] [[KeyPgPtr ptr]]


Revision [14005]

Edited on 2008-12-02 09:50:57 by LaananFisher [Updated: byval]
Additions:
[[KeyPgDeclare declare]] [[KeyPgFunction function]] **Allocate** ( [[KeyPgByval byval]] //count// [[KeyPgAs as]] [[KeyPgInteger integer]] ) [[KeyPgAs as]] [[KeyPgAny any]] [[KeyPgPtr ptr]]
Deletions:
[[KeyPgDeclare declare]] [[KeyPgFunction function]] **Allocate** ( //count// [[KeyPgAs as]] [[KeyPgInteger integer]] ) [[KeyPgAs as]] [[KeyPgAny any]] [[KeyPgPtr ptr]]


Revision [14002]

Edited on 2008-12-01 06:45:00 by RayBritton [changed parameter to count from size, as thoughtout page the parameter is called count not size]
Additions:
[[KeyPgDeclare declare]] [[KeyPgFunction function]] **Allocate** ( //count// [[KeyPgAs as]] [[KeyPgInteger integer]] ) [[KeyPgAs as]] [[KeyPgAny any]] [[KeyPgPtr ptr]]
//result// = **Allocate**( //count// )
##//count//##
Deletions:
[[KeyPgDeclare declare]] [[KeyPgFunction function]] **Allocate** ( //size// [[KeyPgAs as]] [[KeyPgInteger integer]] ) [[KeyPgAs as]] [[KeyPgAny any]] [[KeyPgPtr ptr]]
//result// = **Allocate**( //size// )
##//size//##


Revision [13809]

Edited on 2008-10-23 17:10:12 by CountingPine [changed parameter to count from size, as thoughtout page the parameter is called count not size]
Additions:
'' Bad example of Allocate usage, causing memory leaks
sub BadAllocateExample()
dim p as byte ptr
p = allocate(420) '' assign pointer to new memory
p = allocate(420) '' reassign same pointer to different memory,
'' old address is lost and that memory is leaked
deallocate(p)
'' Main
BadAllocateExample() '' Creates a memory leak
print "Memory leak!"
BadAllocateExample() '' ... and another
print "Memory leak!"
end
- New to ""FreeBASIC""
Deletions:
'' Allocate - "evil" example of a memory leak
sub AllocateExample2()

dim p as byte ptr = 0
p = allocate(420) '' assign pointer to new memory
p = allocate(420) '' reassign same pointer to different memory,
'' old address is lost and that memory is leaked
deallocate(p)
'' Main
AllocateExample2() '' Loosing memory
print "leak example"
AllocateExample2() '' And again
end
- New to FreeBASIC


Revision [13798]

Edited on 2008-10-22 04:08:49 by DoS386 [FBHELP formatting, free on exit]
Additions:
Allocated memory must be deallocated, or returned back to the free store, with ##[[KeyPgDeallocate Deallocate]]## when no longer needed.
It is important to free allocated memory if it's not going to be used anymore. Unused memory that isn't freed is simply wasting memory, and if the address of that memory is somehow overwritten or forgotten, that memory can never be freed. This condition is known as a memory leak, and should be avoided at all costs. Note that leaked memory is always completely freed when the application terminates, either by an "ordinary" exit or crash, so the leak "persists" only as long as the application runs, nevertheless it's a good habit to free any allocated memory inside your application. The following example demonstrates a function with a memory leak, where the address of allocated memory is lost and isn't and can't be freed anymore. If such a function is called frequently, the total amount of memory wasted can add up quickly.
'' Allocate - "evil" example of a memory leak

p = allocate(420) '' assign pointer to new memory
p = allocate(420) '' reassign same pointer to different memory,
'' old address is lost and that memory is leaked
'' Main
AllocateExample2() '' Loosing memory
print "leak example"
AllocateExample2() '' And again
end
Deletions:
Allocated memory must be deallocated, or returned back to the free store, with ##[[KeyPgDeallocate Deallocate]]## when no longer needed.
It is important to free allocated memory if it's not going to be used anymore. Unused memory that isn't freed is simply wasting memory, and if the address of that memory is somehow overwritten or forgotten, that memory can never be freed (this condition is known as a memory leak, and should be avoided at all costs). The following example demonstrates a function with a memory leak, where the address of allocated memory is lost, never to be freed (if this function is called frequently, the memory that is wasted can add up quickly).
p = allocate(420) '' assign pointer to new memory
p = allocate(420) '' reassign pointer to different memory,
'' old address is lost and that memory is leaked
AllocateExample2()
end 0


Revision [13153]

The oldest known version of this page was created on 2008-04-24 15:43:04 by JeffMarshall [FBHELP formatting, free on exit]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode