Re: [fpc-pascal] Array clearing

2017-04-13 Thread Sven Barth via fpc-pascal
Am 13.04.2017 18:06 schrieb "Ryan Joseph" :
>
>
> > On Apr 13, 2017, at 10:29 PM, Sven Barth via fpc-pascal <
fpc-pascal@lists.freepascal.org> wrote:
> >
> > SetLength *does* use a reallocate for this, but since it doesn't give
you any guarantee for its success as its the task of the memory manager to
deal with this, it's easier to assume that the array is indeed copied.
> >
>
> So the real point here is that ReAllocMem will copy and allocate a new
block if the old one can’t be resized, therefore this really isn’t about
SetLength as much as the memory manager itself.

Correct. And since the memory manager is changeable and might implement
whatever behavior it wants nothing fixed can be done for this.

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Hash List

2017-04-13 Thread Giuliano Colla

Il 12/04/2017 15:57, Michael Van Canneyt ha scritto:

we could put it in contnrs, and alias it in inifiles.pp


+1

Giuliano


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Hash List

2017-04-13 Thread Graeme Geldenhuys
On 2017-04-12 14:54, nore...@z505.com wrote:
> maybe it should be pulled out into some other unit so people do 
> not think it is just INI file related?

Agreed!

G.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Array clearing

2017-04-13 Thread Ryan Joseph

> On Apr 13, 2017, at 10:29 PM, Sven Barth via fpc-pascal 
>  wrote:
> 
> SetLength *does* use a reallocate for this, but since it doesn't give you any 
> guarantee for its success as its the task of the memory manager to deal with 
> this, it's easier to assume that the array is indeed copied.
> 

So the real point here is that ReAllocMem will copy and allocate a new block if 
the old one can’t be resized, therefore this really isn’t about SetLength as 
much as the memory manager itself.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Hash List

2017-04-13 Thread African Wild Dog
2017-04-12 10:57 GMT-03:00 Michael Van Canneyt :

we could put it in contnrs, and alias it in inifiles.pp
>
>
+1
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Array clearing

2017-04-13 Thread Sven Barth via fpc-pascal
Am 13.04.2017 14:47 schrieb "Ryan Joseph" :
>
>
> > On Apr 13, 2017, at 7:08 PM, Mattias Gaertner 
wrote:
> >
> >> as I understood from (http://wiki.freepascal.org/Dynamic_array<
http://wiki.freepascal.org/Dynamic_array>), SetLength will create a copy of
the array and free the memory of the shorter array. In this case, a lot of
memory operations and copy operations are performed thus degrading the
performances of the code.
> >
> > Correct.
>
> Why is it copying the array and freeing instead of resizing the existing
block (realloc)? That sounds crazy but I don’t know how memory managers
work.

SetLength *does* use a reallocate for this, but since it doesn't give you
any guarantee for its success as its the task of the memory manager to deal
with this, it's easier to assume that the array is indeed copied.

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Array clearing

2017-04-13 Thread Mattias Gaertner
On Thu, 13 Apr 2017 19:15:13 +0700
Ryan Joseph  wrote:

> > On Apr 13, 2017, at 7:08 PM, Mattias Gaertner  
> > wrote:
> >   
> >> as I understood from 
> >> (http://wiki.freepascal.org/Dynamic_array),
> >>  SetLength will create a copy of the array and free the memory of the 
> >> shorter array. In this case, a lot of memory operations and copy 
> >> operations are performed thus degrading the performances of the code.  
> > 
> > Correct.  
> 
> Why is it copying the array and freeing instead of resizing the existing 
> block (realloc)? That sounds crazy but I don’t know how memory managers work.

It does not free the elements.
It frees the array.

Mattias
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Array clearing

2017-04-13 Thread Ryan Joseph

> On Apr 13, 2017, at 7:08 PM, Mattias Gaertner  
> wrote:
> 
>> as I understood from 
>> (http://wiki.freepascal.org/Dynamic_array),
>>  SetLength will create a copy of the array and free the memory of the 
>> shorter array. In this case, a lot of memory operations and copy operations 
>> are performed thus degrading the performances of the code.
> 
> Correct.

Why is it copying the array and freeing instead of resizing the existing block 
(realloc)? That sounds crazy but I don’t know how memory managers work.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Array clearing

2017-04-13 Thread Sven Barth via fpc-pascal
Am 13.04.2017 13:25 schrieb "MARCOU Gilles" :
>
> Regarding this code:
>
>> SetLength(Array,Length(Array)+1);
>> Array[High(Array)] := …
>
>
> as I understood from (http://wiki.freepascal.org/Dynamic_array),
SetLength will create a copy of the array and free the memory of the
shorter array. In this case, a lot of memory operations and copy operations
are performed thus degrading the performances of the code. Then it would be
unwise to use such strategy: better allocate the size of the array
correctly at the beginning of the run, or resize the array by block, to
decrease the frequency of such operation:
>
>> SetLength(Array,Length(Array)+N);
>
>
> Can somebody confirm (or invalidate) this?

SetLength() uses reallocation for the memory. So it *might* work without
copying though that is not guaranteed.
But in general it's recommended anyway not to do "SetLength(..., ... + 1)"
loops as that will lead to fragmentation of the heap.

Regards
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Array clearing

2017-04-13 Thread Mattias Gaertner
On Thu, 13 Apr 2017 13:17:37 +0200
MARCOU Gilles  wrote:

> Regarding this code:
> 
> > SetLength(Array,Length(Array)+1);
> > Array[High(Array)] := …  
> 
> as I understood from (http://wiki.freepascal.org/Dynamic_array 
> ), SetLength will create a copy of 
> the array and free the memory of the shorter array. In this case, a lot of 
> memory operations and copy operations are performed thus degrading the 
> performances of the code.

Correct.

> Then it would be unwise to use such strategy: better allocate the size
> of the array correctly at the beginning of the run, or resize the
> array by block, to decrease the frequency of such operation:

The usual solution is to grow exponentially:

SetLength(Array,Length(Array)+Max(4,length(Array) div 4))

Mattias
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Array clearing

2017-04-13 Thread MARCOU Gilles
Regarding this code:

> SetLength(Array,Length(Array)+1);
> Array[High(Array)] := …

as I understood from (http://wiki.freepascal.org/Dynamic_array 
), SetLength will create a copy of 
the array and free the memory of the shorter array. In this case, a lot of 
memory operations and copy operations are performed thus degrading the 
performances of the code. Then it would be unwise to use such strategy: better 
allocate the size of the array correctly at the beginning of the run, or resize 
the array by block, to decrease the frequency of such operation:

> SetLength(Array,Length(Array)+N);

Can somebody confirm (or invalidate) this?

Ciao,
Gilles Marcou___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Array clearing

2017-04-13 Thread Benito van der Zander

Hi Ryan,

In the real world is anyone actually going to type that out every time? I’d bet 
most of us have an array class we use and ignore dynamic arrays all together 
because we all need basic operations like “add” and “remove”.


I, for one, have a huge list of array utility functions: 
http://hg.benibela.de/bbutils/file/tip/bbutils.inc


I use arrays rather than classes, because latter are not reference counted

Bye,
BeniBela



On 04/12/2017 04:30 PM, Ryan Joseph wrote:

On Apr 12, 2017, at 9:24 PM, Jürgen Hestermann  
wrote:

SetLength(Array,Length(Array)+1);

You will get an additional element (filled with zeros).
Then you can set

Array[High(Array)] := whateveryouwant;

Well sure, but this kind of code is exactly what programmers abstract and reuse 
so it’s a perfect candidate for a function.

SetLength(Array,Length(Array)+1);
Array[High(Array)] := …

In the real world is anyone actually going to type that out every time? I’d bet 
most of us have an array class we use and ignore dynamic arrays all together 
because we all need basic operations like “add” and “remove”.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Freevision etc.

2017-04-13 Thread Mark Morgan Lloyd
I've not used Freevision/Turbovision before, but am experimenting with 
James Clarke's DialEdit as an experiment to see whether I can create a 
fallback user interface for use if an interactive program is running in 
a shell session. The Lazarus side of things isn't a problem, I know from 
the past how to break out before the GUI is initialised and so on.


My first problem is that there's a name clash between the Freevision and 
LCL variants of some units. I appear to be able to use something like


uses Objects,
  Views in '/usr/local/lib/fpc/3.0.2/units/arm-linux/fv/views',
  Dialogs in '/usr/local/lib/fpc/3.0.2/units/arm-linux/fv/dialogs';

but is it possible to do something like setting up an alias for that 
directory name which will track versions etc.? I'd prefer to not assume 
that there's any predictable relative positioning of the source and unit 
directories.


My second problem is that the Pascal file generated by the dialogue 
editor gives me something like


{ TBDTestBlockDeviceDialogue }

type
PTBDTestBlockDeviceDialogue = ^TTBDTestBlockDeviceDialogue;
TTBDTestBlockDeviceDialogue = object(TTestBlockDeviceDialogue)
constructor Init;
end;

and it's unclear where the TTestBlockDeviceDialogue type is defined. I'm 
sitting down to work through the documentation again.


I'm sure I'll have more problems later :-)

If I can get this working I'm hoping to make the source available as a 
demonstrator somewhere, so I'd very much appreciate suggestions which 
would make this happen.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Array clearing

2017-04-13 Thread Jürgen Hestermann

Am 2017-04-12 um 16:30 schrieb Ryan Joseph:
>> Array[High(Array)] := whateveryouwant;

> SetLength(Array,Length(Array)+1);
> Array[High(Array)] := …
> In the real world is anyone actually going to type that out every time?

Yes, I do this. Typing is not much work for me.
My main focus is on *readable* code (effort for writing is of low priority).
And the 2 lines show very clear what realy happens.

I can also omit the second line and set a value later
while with an Add-function I have to specify a value
for the new array element even if I just want to extend the array only.
I have finer control about what happens.

> I’d bet most of us have an array class we use and ignore dynamic arrays all 
together because we all need basic operations like “add” and “remove”.

I never use classes.
I like dynamic arrays very much.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Bls: Bls: WebAssembly Target

2017-04-13 Thread Mr Bee via fpc-pascal
Pada Kamis, 13 April 2017 13:22, Michael Van Canneyt  
menulis:




> Seriously? Where can we try or test this? This is really a great news! It 
> reminds me of Morfik. :)
Morfik has been, since day 1, the inspiration for this.

I knew it! ^_^


> Hope the development will continue.
It is. The compiler is progressing well. Language is pretty much complete ona 
D7 level. Currently work is done on implementing RTTI.

O, c'mon Michael… please release it. Even if it isn't fully ready, as beta or 
preview or whatever. We'd like to try it out! I can't wait to test it. :)
Regards,
–Mr Bee
   ___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Array clearing

2017-04-13 Thread Ryan Joseph

> On Apr 12, 2017, at 9:24 PM, Jürgen Hestermann  
> wrote:
> 
> SetLength(Array,Length(Array)+1);
> 
> You will get an additional element (filled with zeros).
> Then you can set
> 
> Array[High(Array)] := whateveryouwant;

Well sure, but this kind of code is exactly what programmers abstract and reuse 
so it’s a perfect candidate for a function. 

SetLength(Array,Length(Array)+1);
Array[High(Array)] := …

In the real world is anyone actually going to type that out every time? I’d bet 
most of us have an array class we use and ignore dynamic arrays all together 
because we all need basic operations like “add” and “remove”.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Bls: WebAssembly Target

2017-04-13 Thread Michael Van Canneyt



On Thu, 13 Apr 2017, Mr Bee via fpc-pascal wrote:






Pada Sabtu, 18 Maret 2017 0:54, Michael Van Canneyt  
menulis:


You'll design a web app in the lazarus IDE (or Delphi IDE, for that matter).
The app will be compiled to Javascript.


Current thinking is that that there will be 2 "modes":
- "Free" Mode, where the CSS will determine the actual runtime look.
  The IDE will just create the DOM structure.
- "Exact" mode, where the app will look in the browser as it looks in the IDE.
  the necessary CSS will be generated for this.


In both modes of course the IDE and object inspector will be used to create
event handlers and whatnot in Pascal…


But this is all still under heavy development.


Seriously? Where can we try or test this? This is really a great news! It 
reminds me of Morfik. :)


Morfik has been, since day 1, the inspiration for this.


Hope the development will continue.


It is. 
The compiler is progressing well. Language is pretty much complete on

a D7 level. Currently work is done on implementing RTTI.

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal