Re: [fpc-pascal] For ..in GetEnumerator Allocation

2017-10-05 Thread Martok
Am 04.10.2017 um 11:26 schrieb Michael Van Canneyt: > As an alternative you can create an object enumeator. > It's simply allocated on the stack, and you can reset it in the enumerator > operator. That is by far the easiest solution (records need $modeswitch advancedrecords, but are otherwise

Re: [fpc-pascal] For ..in GetEnumerator Allocation

2017-10-04 Thread Ryan Joseph
> On Oct 4, 2017, at 10:03 PM, Michael Van Canneyt > wrote: > > Newinstance allocates the memory for a new instance of the class. > By default this is GetMem(instanceSize). So you override the class method Newinstance in the enumerator class and return the same block

Re: [fpc-pascal] For ..in GetEnumerator Allocation

2017-10-04 Thread Ryan Joseph
> On Oct 4, 2017, at 5:19 PM, Marco van de Voort wrote: > > Yup, or a record. See e.g. http://www.stack.nl/~marcov/lightcontainers.zip This seems like the simplest more efficient method. Does FPC just know it’s a record internally and not try to dealloc it? GetEnumerator

Re: [fpc-pascal] For ..in GetEnumerator Allocation

2017-10-04 Thread Mattias Gaertner
On Wed, 4 Oct 2017 15:41:27 +0700 Ryan Joseph wrote: > As I understand the for..in loop GetEnumerator method is expected to create a > new object each time it’s called and FPC destroys it later when the loos is > finished. Can I retain the enumerator and just reset

Re: [fpc-pascal] For ..in GetEnumerator Allocation

2017-10-04 Thread Michael Van Canneyt
On Wed, 4 Oct 2017, Ryan Joseph wrote: On Oct 4, 2017, at 4:26 PM, Michael Van Canneyt wrote: You can do so by overriding the newinstance and it's sister method of your enumerator class. Can you explain how this works or give an example? Not sure how these gets

Re: [fpc-pascal] For ..in GetEnumerator Allocation

2017-10-04 Thread Ryan Joseph
> On Oct 4, 2017, at 4:26 PM, Michael Van Canneyt > wrote: > > You can do so by overriding the newinstance and it's sister method of > your enumerator class. Can you explain how this works or give an example? Not sure how these gets around the problem of alloc/dealloc

Re: [fpc-pascal] For ..in GetEnumerator Allocation

2017-10-04 Thread Graeme Geldenhuys
On 2017-10-04 09:41, Ryan Joseph wrote: I’d like to remove all these alloc/deallocs so I can use for..in more efficiently in tight loops. I've had the same requirement, and also needed that functionality before the for..in syntax existed in FPC. Take a look at my Iterator interface and

Re: [fpc-pascal] For ..in GetEnumerator Allocation

2017-10-04 Thread Marco van de Voort
In our previous episode, Michael Van Canneyt said: > As an alternative you can create an object enumeator. > It's simply allocated on the stack, and you can reset it in the enumerator > operator. Yup, or a record. See e.g. http://www.stack.nl/~marcov/lightcontainers.zip

Re: [fpc-pascal] For ..in GetEnumerator Allocation

2017-10-04 Thread Michael Van Canneyt
On Wed, 4 Oct 2017, Ryan Joseph wrote: As I understand the for..in loop GetEnumerator method is expected to create a new object each time it’s called and FPC destroys it later when the loos is finished. Can I retain the enumerator and just reset it in-between calls? I’d like to remove all

[fpc-pascal] For ..in GetEnumerator Allocation

2017-10-04 Thread Ryan Joseph
As I understand the for..in loop GetEnumerator method is expected to create a new object each time it’s called and FPC destroys it later when the loos is finished. Can I retain the enumerator and just reset it in-between calls? I’d like to remove all these alloc/deallocs so I can use for..in