Revision history for KeyPgOpPlacementNew


Revision [22667]

Last edited on 2019-05-03 01:40:59 by fxm [Clarified that New [] is one-dimensional]
Additions:
##**Placement New[]**## operator is the (one-dimensional) array-version of the ##**Placement New**## operator and constructs the specified number of objects from the specified memory location. The default constructor for the type will be used to set the initial values for each item.
Deletions:
##**Placement New[]**## operator is the array-version of the ##**Placement New**## operator and constructs the specified number of objects from the specified memory location. The default constructor for the type will be used to set the initial values for each item.


Revision [22541]

Edited on 2018-12-28 13:18:05 by fxm [Added sentence for describing the Placement New[] operator syntax]
Additions:
##**Placement New[]**## operator is the array-version of the ##**Placement New**## operator and constructs the specified number of objects from the specified memory location. The default constructor for the type will be used to set the initial values for each item.


Revision [22456]

Edited on 2018-09-01 15:42:22 by fxm [Page updated while 'Operator New Overload' page creation]
Additions:
Because it does not provide any dynamic memory allocation process, the ##**Placement New**## operator (unlike the ##[[KeyPgOpNew|New Expression]]## operator) does not allow any overloading by a member operator for user-defined types.


Revision [22440]

Edited on 2018-08-29 16:13:38 by fxm ['New' -> 'New Expression', 'Delete' -> 'Delete Statement']
Additions:
See examples below for proper ##**Placement New**## operator usage.
Deletions:
See examples below for proper ##**Placement New**## usage.


Revision [22438]

Edited on 2018-08-29 13:57:31 by fxm ['New' -> 'New Expression', 'Delete' -> 'Delete Statement']
Additions:
See examples below for proper ##**Placement New**## usage.
Deletions:
See examples below for proper //placement new// usage.


Revision [22424]

Edited on 2018-08-29 08:25:27 by fxm ['New' -> 'New Expression', 'Delete' -> 'Delete Statement']
Deletions:
==={{color text="Update in progress (@fxm)." c="red"}}===


Revision [22414]

Edited on 2018-08-29 07:38:27 by fxm [Update in progress]
Additions:
It is incorrect to call ##[[KeyPgOpDelete|Delete Statement]]## on the address. The proper way is to only call the destructor if one exists (implicitly or explicitly), with syntax as for a member method by using member access operator.
- ##[[KeyPgOpNew|New Expression]]##
Deletions:
It is incorrect to call ##[[KeyPgOpDelete|Delete]]## on the address. The proper way is to only call the destructor if one exists (implicitly or explicitly), with syntax as for a member method by using member access operator.
- ##[[KeyPgOpNew|New]]##


Revision [22397]

Edited on 2018-08-29 04:08:01 by fxm [Update in progress]
Additions:
==={{color text="Update in progress (@fxm)." c="red"}}===


Revision [22369]

Edited on 2018-08-25 07:57:55 by fxm [Added note highlighting the risk to use PLACEMENT NEW[] in some cases]
Additions:
**Note:** Using ##//pointer// = **New**(//address//)//datatype//[//count//]## may be unsafe if ##//pointer//## was declared with a type different from ##//datatype//## (for sub-type polymorphism purpose for example), because the pointer arithmetic fails to access the elements if the pointer type size is different from the size of ##//datatype//## (when using ##{{fbdoc item="keyword" value="KeyPgOpPtrIndex|Operator [] (Pointer index)"}}## or adding an offset (element number) to the pointer).
Deletions:
**Note:** Using ##//pointer// = **New**(//address//)//datatype//[//count//]## may be unsafe if ##//pointer//## was declared with a type different from ##//datatype//## because the pointer arithmetic fails to access the elements if the pointer type size is different from the size of ##//datatype//## (when using ##{{fbdoc item="keyword" value="KeyPgOpPtrIndex|Operator [] (Pointer index)"}}## or adding an offset (element number) to the pointer).


Revision [22367]

Edited on 2018-08-25 04:27:24 by fxm [Added note highlighting the risk to use PLACEMENT NEW[] in some cases]
Additions:
**Note:** Using ##//pointer// = **New**(//address//)//datatype//[//count//]## may be unsafe if ##//pointer//## was declared with a type different from ##//datatype//## because the pointer arithmetic fails to access the elements if the pointer type size is different from the size of ##//datatype//## (when using ##{{fbdoc item="keyword" value="KeyPgOpPtrIndex|Operator [] (Pointer index)"}}## or adding an offset (element number) to the pointer).


Revision [22323]

Edited on 2018-05-28 05:56:04 by fxm [Wording]
Additions:
For simple types, like integers, an initial value can be given. For types without ##[[KeyPgConstructor|constructor]]##s, initial values can be specified for each field (either with default initializer at data-field declaration, or with initializer list as in ##**New** //datatype// (**initializers, ..**)## if all type data-fields are numeric primitives only and without any default initializers). For types with at least one constructor, the initialize list (if any) must match an existing constructor. If no initializers are given, the default values for those types will be set.
Deletions:
For simple types, like integers, an initial value can be given. For types without ##[[KeyPgConstructor|constructor]]##s, initial values can be specified for each field (either with default initializer at data-field declaration, or with initializer list as in ##**New** //datatype// (**initializers, ..**)## if all type data-fields are numeric primitives only and without any default initializers). Types that have constructors can have their constructors called by ##**Placement New**## as well. If no initializers are given, the default values for those types will be set.


Revision [21444]

Edited on 2016-04-30 12:01:45 by fxm [Reworded in description]
Additions:
Memory is **not** allocated when using the ##**Placement New**## operator. Instead, the memory at the specified ##//address//## is used (the provided memory size must be large enough to contain all the placement).
Deletions:
Memory is **not** allocated when using the ##**Placement New**## operator. Instead, the memory at the specified ##//address//## is used (the available memory must be large enough to contain all the placement).


Revision [21443]

Edited on 2016-04-30 11:24:54 by fxm [Reworded in description]
Additions:
Memory is **not** allocated when using the ##**Placement New**## operator. Instead, the memory at the specified ##//address//## is used (the available memory must be large enough to contain all the placement).
Deletions:
Memory is **not** allocated when using the ##**Placement New**## operator. Instead, the memory at the specified ##//address//## is used.


Revision [21441]

Edited on 2016-04-30 11:07:51 by fxm [Reworded in description]
Additions:
For simple types, like integers, an initial value can be given. For types without ##[[KeyPgConstructor|constructor]]##s, initial values can be specified for each field (either with default initializer at data-field declaration, or with initializer list as in ##**New** //datatype// (**initializers, ..**)## if all type data-fields are numeric primitives only and without any default initializers). Types that have constructors can have their constructors called by ##**Placement New**## as well. If no initializers are given, the default values for those types will be set.
Specifying an initial value of ##[[KeyPgAny|Any]]##, as in ##**New**(//address//)//datatype// (**Any**)## or ##**New**(//address//)//datatype//[//count//] {**Any**}## will not initialize the data. This is only valid on data types that do not have constructors (otherwise for data types with constructors, syntax of simple pointer conversion, like //Cptr(datatype Ptr, address)//, can be substituted to the invalid use of New...Any).
Deletions:
For simple types, like integers, an initial value can be given. For types without ##[[KeyPgConstructor|constructor]]##s, initial values can be specified for each field. Types that have constructors can have their constructors called by ##**Placement New**## as well. If no initializers are given, the default values for those types will be set.
Specifying an initial value of ##[[KeyPgAny|Any]]##, as in ##**New**(//address//)//datatype//(**Any**)## or ##**New**(//address//)//datatype//[//count//]{**Any**}## will not initialize the data. This is only valid on data types that do not have constructors (otherwise for data types with constructors, syntax of simple pointer conversion, like //Cptr(datatype Ptr, address)//, can be substituted to the invalid use of New...Any).


Revision [21053]

Edited on 2016-03-13 08:29:20 by fxm [Formatting]

No Differences

Revision [20403]

Edited on 2016-02-10 16:05:19 by DkLwikki [Update link format]
Additions:
//result// = **New(//address//)** //[[DataType|datatype]]//
//result// = **New(//address//)** //[[DataType|datatype]]// ( //initializers//, ... )
//result// = **New(//address//)** //[[DataType|datatype]]//**[** //count// **]**
A pointer of type ##[[DataType|datatype]]## to the newly constructed data.
For simple types, like integers, an initial value can be given. For types without ##[[KeyPgConstructor|constructor]]##s, initial values can be specified for each field. Types that have constructors can have their constructors called by ##**Placement New**## as well. If no initializers are given, the default values for those types will be set.
It is incorrect to call ##[[KeyPgOpDelete|Delete]]## on the address. The proper way is to only call the destructor if one exists (implicitly or explicitly), with syntax as for a member method by using member access operator.
Specifying an initial value of ##[[KeyPgAny|Any]]##, as in ##**New**(//address//)//datatype//(**Any**)## or ##**New**(//address//)//datatype//[//count//]{**Any**}## will not initialize the data. This is only valid on data types that do not have constructors (otherwise for data types with constructors, syntax of simple pointer conversion, like //Cptr(datatype Ptr, address)//, can be substituted to the invalid use of New...Any).
- Only available in the //[[CompilerOptlang|-lang fb]]// dialect.
- ##[[KeyPgDestructor|Destructor]]##
- ##[[KeyPgOpNew|New]]##
Deletions:
//result// = **New(//address//)** //[[DataType datatype]]//
//result// = **New(//address//)** //[[DataType datatype]]// ( //initializers//, ... )
//result// = **New(//address//)** //[[DataType datatype]]//**[** //count// **]**
A pointer of type ##[[DataType datatype]]## to the newly constructed data.
For simple types, like integers, an initial value can be given. For types without ##[[KeyPgConstructor constructor]]##s, initial values can be specified for each field. Types that have constructors can have their constructors called by ##**Placement New**## as well. If no initializers are given, the default values for those types will be set.
It is incorrect to call ##[[KeyPgOpDelete Delete]]## on the address. The proper way is to only call the destructor if one exists (implicitly or explicitly), with syntax as for a member method by using member access operator.
Specifying an initial value of ##[[KeyPgAny Any]]##, as in ##**New**(//address//)//datatype//(**Any**)## or ##**New**(//address//)//datatype//[//count//]{**Any**}## will not initialize the data. This is only valid on data types that do not have constructors (otherwise for data types with constructors, syntax of simple pointer conversion, like //Cptr(datatype Ptr, address)//, can be substituted to the invalid use of New...Any).
- Only available in the //[[CompilerOptlang -lang fb]]// dialect.
- ##[[KeyPgDestructor Destructor]]##
- ##[[KeyPgOpNew New]]##


Revision [17088]

Edited on 2014-06-06 13:17:39 by FxMwikki [Clarified destroying of object in case of Placement New]

No Differences

Revision [17087]

Edited on 2014-06-06 08:18:54 by FxMwikki [Clarified destroying of object in case of Placement New]
Additions:
It is incorrect to call ##[[KeyPgOpDelete Delete]]## on the address. The proper way is to only call the destructor if one exists (implicitly or explicitly), with syntax as for a member method by using member access operator.
Type Rational
As Integer numerator, denominator
Declare Constructor ( Byval n As Integer, Byval d As Integer )
As String ratio = "/"
End Type
Constructor Rational ( Byval n As Integer, Byval d As Integer )
This.numerator = n
This.denominator = d
End Constructor
Scope

Dim As Any Ptr ap = CAllocate(Len(Rational))

Dim As Rational Ptr r = New (ap) Rational( 3, 4 )

Print ap, r

Print r->numerator & r->ratio & r->denominator
'' delete must not be used with placement new
'' destroying must be done explicitly if a destructor exists (implicitly or explicitly)
'' (in this example, the var-string member induces an implicit destructor)
Deallocate( ap )
End Scope
- ##[[KeyPgDestructor Destructor]]##
Deletions:
It is incorrect to call ##[[KeyPgOpDelete Delete]]## on the address (otherwise, the memory is deallocated). The proper way is to only call the destructor (with syntax as for a member method, using member access operator).
type Rational
as integer numerator, denominator
Declare Destructor ( )
end type
Destructor Rational ( )
End Destructor
scope
dim as any ptr ap = callocate(len(Rational))
dim as Rational ptr r = new (ap) Rational( 3, 4 )
print ap, r
print r->numerator & "/" & r->denominator
'' destroying must be done explicitly, because delete will automatically free the memory
'' and that isn't always okay when using placement new. ALWAYS explicitly call the destructor.
deallocate( ap )
end scope
- ##[[KeyPgOpDelete Delete]]##


Revision [17058]

Edited on 2014-04-27 07:54:51 by FxMwikki [NEW/DELETE and NEW[]/DELETE[] can now be used with the dynamic STRING data type]
Deletions:
The ##**Placement New**## operator cannot be directly used with ##[[KeyPgString String]]##, but works with ##[[KeyPgType UDT]]## containing string.


Revision [16988]

Edited on 2014-01-10 03:45:17 by FxMwikki [Added substitutive syntax for "New...Any" invalid when types with constructors]
Additions:
Specifying an initial value of ##[[KeyPgAny Any]]##, as in ##**New**(//address//)//datatype//(**Any**)## or ##**New**(//address//)//datatype//[//count//]{**Any**}## will not initialize the data. This is only valid on data types that do not have constructors (otherwise for data types with constructors, syntax of simple pointer conversion, like //Cptr(datatype Ptr, address)//, can be substituted to the invalid use of New...Any).
Deletions:
Specifying an initial value of ##[[KeyPgAny Any]]##, as in ##**New**(//address//)//datatype//(**Any**)## or ##**New**(//address//)//datatype//[//count//]{**Any**}## will not initialize the data. This is only valid on data types that do not have constructors.


Revision [16491]

Edited on 2012-12-09 07:43:56 by FxMwikki [Example: since fbc 0.25, implicit ctor/dtor is not automatically added when called as member method]
Additions:
Declare Destructor ( )
Destructor Rational ( )
End Destructor


Revision [16423]

Edited on 2012-11-08 14:07:33 by FxMwikki [Parameter "size" removed. Definition of "data type", "count" and "return value" reworded.]
Additions:
name of the data type to construct.
Number of elements to construct.
A pointer of type ##[[DataType datatype]]## to the newly constructed data.
Deletions:
##//size//##
number of bytes to allocate.
name of the data type to create.
Number of elements to allocate.
A pointer of type ##[[DataType datatype]]## to the newly allocated data.


Revision [16176]

Edited on 2012-05-15 11:29:30 by CountingPine [Formatting, combine almost-duplicated sentences]
Additions:
A pointer of type ##[[DataType datatype]]## to the newly allocated data.
For simple types, like integers, an initial value can be given. For types without ##[[KeyPgConstructor constructor]]##s, initial values can be specified for each field. Types that have constructors can have their constructors called by ##**Placement New**## as well. If no initializers are given, the default values for those types will be set.
Specifying an initial value of ##[[KeyPgAny Any]]##, as in ##**New**(//address//)//datatype//(**Any**)## or ##**New**(//address//)//datatype//[//count//]{**Any**}## will not initialize the data. This is only valid on data types that do not have constructors.
Deletions:
A pointer of type [[DataType datatype]] to the newly allocated data.
For simple types, like integers, an initial value can be given. For types without constructors, initial values can be specified for each field. Types that have constructors can have their constructors called by ##**Placement New**## as well. If no initializers are given, the default values for those types will be set.
Specifying an initial value of ##[[KeyPgAny Any]]##, as in ##new(address) datatype(any)## will not initialize the data. This is only valid on data types that do not have constructors.
Specifying an initial value of ##[[KeyPgAny Any]]##, as in ##new(address) datatype[count]{any}## will not initialize the data. This is only valid on data types that do not have constructors.


Revision [15591]

Edited on 2011-12-29 14:34:47 by FxMwikki [Complement about destructor method.]
Additions:
It is incorrect to call ##[[KeyPgOpDelete Delete]]## on the address (otherwise, the memory is deallocated). The proper way is to only call the destructor (with syntax as for a member method, using member access operator).
Deletions:
It is incorrect to call ##[[KeyPgOpDelete Delete]]## on the address (otherwise, the memory is deallocated). The proper way is to only call the destructor (with syntax as for a member method).


Revision [15586]

Edited on 2011-12-29 09:40:45 by FxMwikki [Complement about destructor method.]
Additions:
Memory is **not** allocated when using the ##**Placement New**## operator. Instead, the memory at the specified ##//address//## is used.
It is incorrect to call ##[[KeyPgOpDelete Delete]]## on the address (otherwise, the memory is deallocated). The proper way is to only call the destructor (with syntax as for a member method).
See examples below for proper //placement new// usage.
Deletions:
Memory is **not** allocated when using the ##**Placement New**## operator. Instead, the memory at the specified ##//address//## is used. It is incorrect to call ##[[KeyPgOpDelete Delete]]## on the address. See examples below for proper //placement new// usage.


Revision [15184]

Edited on 2011-08-17 05:33:43 by FxMwikki [Complement about destructor method.]
Additions:
The ##**Placement New**## operator cannot be directly used with ##[[KeyPgString String]]##, but works with ##[[KeyPgType UDT]]## containing string.
Deletions:
The ##**Placement New**## operator cannot be used with ##[[KeyPgString String]]##, but can be used with ##[[KeyPgType UDT]]## containing string.


Revision [15182]

Edited on 2011-08-17 03:35:28 by FxMwikki [Complement about destructor method.]
Additions:
The ##**Placement New**## operator cannot be used with ##[[KeyPgString String]]##, but can be used with ##[[KeyPgType UDT]]## containing string.
Deletions:
The ##**Placement New**## operator cannot be used with ##[[KeyPgString String]]##, but can be used with ##[[KeyPgType UDT]]## containing ##[[KeyPgString String]]##.


Revision [15180]

Edited on 2011-08-17 01:59:37 by FxMwikki [Complement about destructor method.]
Additions:
The ##**Placement New**## operator cannot be used with ##[[KeyPgString String]]##, but can be used with ##[[KeyPgType UDT]]## containing ##[[KeyPgString String]]##.
Deletions:
The ##**Placement New**## operator cannot be used with ##[[KeyPgString String]]##, but can be used with UDT containing ##[[KeyPgString String]]##.


Revision [15178]

Edited on 2011-08-17 01:50:08 by FxMwikki [Complement about destructor method.]
Additions:
The ##**Placement New**## operator cannot be used with ##[[KeyPgString String]]##, but can be used with UDT containing ##[[KeyPgString String]]##.
Deletions:
The ##**Placement New**## operator cannot be used with ##[[KeyPgString String]]##.


Revision [15176]

Edited on 2011-08-11 12:00:39 by FxMwikki [Complement about destructor method.]
Additions:
The ##**Placement New**## operator cannot be used with ##[[KeyPgString String]]##.


Revision [14395]

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


Revision [12662]

The oldest known version of this page was created on 2008-03-02 11:07:07 by JeffMarshall [Remove CamelCase links in "New to FreeBASIC"]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode