Thread View: borland.public.delphi.basm
8 messages
8 total messages
Started by Tony Werten
Tue, 17 Sep 2002 13:59
Cache optimization
Author: Tony Werten
Date: Tue, 17 Sep 2002 13:59
Date: Tue, 17 Sep 2002 13:59
17 lines
1472 bytes
1472 bytes
Hi all, in my chessprogram I have a large hashtable (256 MB), each entry is 16 byte and I use 2 (folowing) entries each acces . My questions: What happens when I acces this table ie how much is transferred to cache ? If this is more than 32 bytes, can I it force to not cache more ? ( Next entry will be somewhere else and I don't want other important information to be thrown out of cache ) This accessing will happen about 300,000-400,000 times a second so any optimization will help a lot. Thanks in advance, Tony
Re: Cache optimization
Author: Tony Werten
Date: Tue, 17 Sep 2002 16:08
Date: Tue, 17 Sep 2002 16:08
45 lines
2122 bytes
2122 bytes
"Torjei Kvinen" <torjei@hahaha_bluezone.no> schreef in bericht news:3d88958d@newsgroups.borland.com... > "Tony Werten" <a.werten@cs.unimaas.nl> wrote in message > > > in my chessprogram I have a large hashtable (256 MB) > > You may consider not to cache it at all? Take a look at VirtualAlloc and > PAGE_NOCACHE. I'm a little confused here. I have: hashtable:array[0..1] of tHashtableentry How do I go on ? Virtualalloc(hashtable,... ) or Virtualalloc(@hashtable,....) doesn't seem to work Tony > > > > What happens when I acces this table ie how much is transferred to cache ? > > On Pentium (including PIII) it's 32 bytes. P4 has 64 bytes. > > This link contains some relevant info: (sorry about the word wrapping) > http://cedar.intel.com/cgi-bin/ids.dll/content/content.jsp?cntKey=Generic+Ed > itorial%3a%3ap4_vs_p3&cntType=IDS_EDITORIAL&catCode=BDS > > > > If this is more than 32 bytes, can I it force to not cache more ? > > No, it's all or nothing on page size (4 KBytes) boundaries. > > > -- > Regards > Torjei Kvinen > > >
Re: Cache optimization
Author: Tony Werten
Date: Tue, 17 Sep 2002 21:03
Date: Tue, 17 Sep 2002 21:03
55 lines
2055 bytes
2055 bytes
tHashtableentry=record
key:int64;
score:integer;
flags:cardinal;
end;
>
> function AllocNoCacheMem(const Size : Integer) : Pointer;
> begin
> Result := VirtualAlloc(nil, Size, MEM_COMMIT,
> PAGE_READWRITE or PAGE_NOCACHE);
> end;
>
> procedure FreeNoCacheMem(const Mem : Pointer);
> begin
> VirtualFree(Mem, 0, MEM_RELEASE);
> end;
>
>
> type
> tHashtable = array[0..1] of tHashtableentry;
> pHashtable = ^tHashtable;
>
> var
> Hashtable = pHashtable;
I suppose the = has to be a : ?
>
> begin
> Hashtable := AllocNoCacheMem(256*1024*1024);
>
At this point i can get hashtable[0],hashtable[1] but hashtable[3] gives a
"subrange expression violates subrange bounds"
What I want is fe hashtable[0,0] but then I get a "array type required"
If I change pHashtable=array of tHashtable then things go right until I
actually acces an entry.
Tony
> ..
>
> FreeNoCacheMem(Hashtable);
> end;
>
>
> --
> Regards
> Torjei Kvinen
>
>
>
Re: Cache optimization
Author: Torjei Kvinen
Date: Wed, 18 Sep 2002 16:22
Date: Wed, 18 Sep 2002 16:22
41 lines
1828 bytes
1828 bytes
"Tony Werten" <a.werten@cs.unimaas.nl> wrote in message
> > You may consider not to cache it at all? Take a look at VirtualAlloc and
> > PAGE_NOCACHE.
>
> I'm a little confused here.
>
> I have: hashtable:array[0..1] of tHashtableentry
function AllocNoCacheMem(const Size : Integer) : Pointer;
begin
Result := VirtualAlloc(nil, Size, MEM_COMMIT,
PAGE_READWRITE or PAGE_NOCACHE);
end;
procedure FreeNoCacheMem(const Mem : Pointer);
begin
VirtualFree(Mem, 0, MEM_RELEASE);
end;
type
tHashtable = array[0..1] of tHashtableentry;
pHashtable = ^tHashtable;
var
Hashtable = pHashtable;
begin
Hashtable := AllocNoCacheMem(256*1024*1024);
..
FreeNoCacheMem(Hashtable);
end;
--
Regards
Torjei Kvinen
Re: Cache optimization
Author: Torjei Kvinen
Date: Wed, 18 Sep 2002 19:41
Date: Wed, 18 Sep 2002 19:41
14 lines
1447 bytes
1447 bytes
"Tony Werten" <a.werten@cs.unimaas.nl> wrote in message > I get an adress back but when I acces "hashtable^[0,0].key" I get an > accesviolation. You have to show us more of you are doing, and the definition of hashtable. To find out if something is wrong with the memory allocated by VirtualAlloc, you can try AllocMem (in SysUtils) or GetMem instead. -- Regards Torjei Kvinen
Re: Cache optimization
Author: Torjei Kvinen
Date: Wed, 18 Sep 2002 21:09
Date: Wed, 18 Sep 2002 21:09
30 lines
1915 bytes
1915 bytes
"Tony Werten" <a.werten@cs.unimaas.nl> wrote in message
> At this point i can get hashtable[0],hashtable[1] but hashtable[3] gives a
> "subrange expression violates subrange bounds"
type
tHashtable = array[0..(MaxInt div SizeOf(tHashtableentry))-1] of
tHashtableentry;
Or you can turn of range checking, see {$RANGECHECKS OFF}
> What I want is fe hashtable[0,0] but then I get a "array type required"
This is a two dimensional table, current definition of tHashtable is only
one dimension?
> If I change pHashtable=array of tHashtable then things go right until I
> actually acces an entry.
Here is how you define a two dimensional table.
type
tHashtable = array[0..4095, 0..4095] of tHashtableentry;
--
Regards
Torjei Kvinen
Re: Cache optimization
Author: Tony Werten
Date: Wed, 18 Sep 2002 22:01
Date: Wed, 18 Sep 2002 22:01
31 lines
1708 bytes
1708 bytes
> This is a two dimensional table, current definition of tHashtable is only > one dimension? > > > > If I change pHashtable=array of tHashtable then things go right until I > > actually acces an entry. Thanks, I think I have the idea. You basicly lay the definition over the reserved memoryspace ? > > Here is how you define a two dimensional table. > > type > tHashtable = array[0..4095, 0..4095] of tHashtableentry; OK, but now for the dishwasher. I need array[0..x,0..1] but I won't know x until runtime. cheers, Tony > > > -- > Regards > Torjei Kvinen > > >
Re: Cache optimization
Author: Tony Werten
Date: Thu, 19 Sep 2002 10:44
Date: Thu, 19 Sep 2002 10:44
67 lines
2458 bytes
2458 bytes
Managed to get it to work. It makes exactly 0% difference :((( Appearantly my cache gets killed in other places to. Tony "Tony Werten" <a.werten@cs.unimaas.nl> schreef in bericht news:3d88e19b$2@newsgroups.borland.com... > tHashtableentry=record > key:int64; > score:integer; > flags:cardinal; > end; > > > > > function AllocNoCacheMem(const Size : Integer) : Pointer; > > begin > > Result := VirtualAlloc(nil, Size, MEM_COMMIT, > > PAGE_READWRITE or PAGE_NOCACHE); > > end; > > > > procedure FreeNoCacheMem(const Mem : Pointer); > > begin > > VirtualFree(Mem, 0, MEM_RELEASE); > > end; > > > > > > type > > tHashtable = array[0..1] of tHashtableentry; > > pHashtable = ^tHashtable; > > > > var > > Hashtable = pHashtable; > > I suppose the = has to be a : ? > > > > > begin > > Hashtable := AllocNoCacheMem(256*1024*1024); > > > > At this point i can get hashtable[0],hashtable[1] but hashtable[3] gives a > "subrange expression violates subrange bounds" > > What I want is fe hashtable[0,0] but then I get a "array type required" > > If I change pHashtable=array of tHashtable then things go right until I > actually acces an entry. > > Tony > > > .. > > > > FreeNoCacheMem(Hashtable); > > end; > > > > > > -- > > Regards > > Torjei Kvinen > > > > > > > >
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads