Recent

Author Topic: TPointerList  (Read 8929 times)

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: TPointerList
« Reply #15 on: December 25, 2014, 10:24:49 pm »
I see what's happening, you are not supposed to use TPointerList in variable declaration. Instead use PPointerList to make its size dynamic. It is very situational and i can't give a very smart example of its use. For most cases you are better off using TList or TObjectList.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: TPointerList
« Reply #16 on: December 26, 2014, 05:30:01 am »
Thanks Laksen. I assume your description is correct, but Demand Paging itself is not new. A paper from 1999 has a reference that dates back to 1982. Wikipedia page that talks about Demand Paging was written in 2004.
It's not new, indeed. Both Windows and Linux claim to implement it. But it seems something is different in Windows.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: TPointerList
« Reply #17 on: December 26, 2014, 05:43:37 am »
Thanks Laksen. I assume your description is correct, but Demand Paging itself is not new. A paper from 1999 has a reference that dates back to 1982. Wikipedia page that talks about Demand Paging was written in 2004.
It's not new, indeed. Both Windows and Linux claim to implement it. But it seems something is different in Windows.
Could the difference be that if my application has a 600 MB array, prior to touching any part of that array, Windows reports that memory usage, while Linux does not?

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: TPointerList
« Reply #18 on: December 26, 2014, 06:35:04 am »
To be quite honest, there is only 1 reason that TPointerList has size that big: Range checking, and even then it would propably just give a compiler hint not error.

It is declared like this currently:
Code: [Select]
TPointerList = array[0..MaxListSize - 1] of Pointer;
But for its actual use and range checking disabled it could have been:
Code: [Select]
TPointerList = array[0..0] of Pointer;
This is the more relevant part:
Code: [Select]
PPointerList = ^TPointerList;
Ok here's 1 example:
Code: [Select]
procedure NullArray(const arr: PPointerList; count: integer);
var k: integer;
begin
  for k:=0 to count-1 do
    arr^[k]:=nil;
end;

procedure A;
var
  arr: array[0..9] of pointer;
  dynArr: array of pointer;
begin 
  NullArray(@arr, 10);

  Setlength(dynArr, 10);
  NullArray(@dynArr[0], 10);
end;
« Last Edit: December 26, 2014, 06:39:50 am by User137 »

 

TinyPortal © 2005-2018