multi dimensional array example

S

Skybuck Flying

Hello,

How to convert this Delphi code for Win32 to C or C++ Win32 code ?

var
vArray : array of array of array of integer;

x,y,z : integer;

begin
SetLength( vArray, 200, 200, 200 );

for x := 0 to 199 do
begin
for y := 0 to 199 do
begin
for z := 0 to 199 do
begin
vArray[ x, y, z ] := 123456789;
end;
end;
end;

vArray := nil;
end;

Bye,
Skybuck.
 
R

Richard Heathfield

Skybuck Flying said:
Hello,

How to convert this Delphi code for Win32 to C or C++ Win32 code ?

You could start by apologising for your systematic and prolonged Usenet
abuse over several years. People aren't usually all that interested in
helping trolls with technical problems.
 
S

Skybuck Flying

Richard Heathfield said:
Skybuck Flying said:


You could start by apologising for your systematic and prolonged Usenet
abuse over several years. People aren't usually all that interested in
helping trolls with technical problems.

I don't ever apologise to incompetent fools like you.

Bye,
Skybuck.
 
R

Richard Heathfield

Skybuck Flying said:
I don't ever apologise to incompetent fools like you.

That figures. Just a couple of points, though, before I leave you to your
cess-pool of abuse: someone who can't do what you're asking to do - e.g.
you - is incompetent, and someone who insults those from whom he seeks help
- e.g. you - is a fool. The wise are not overly concerned by the opinions
of such people.
 
S

Skybuck Flying

Skybuck Flying said:
First I stick my big dick in your mouth so you have something to chew on
since you obviously need it to shut up your nagging foul mouth :D

And after I do that I post my solution which you obviously lack.

This code nicely demonstrates the different access times for RAM chips
depending on index order/memory layout <- which is much more clear in my
equally competent delphi code.

// ArrayAccessTest.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include "windows.h"
#include "stdlib.h"
int _tmain(int argc, _TCHAR* argv[])
{
//int ***vArray;
int Tick1;
int Tick2;
int Interval;
int x,y,z;
int *vArray = new int[200*200*200];
Tick1 = GetTickCount();
for (x=0; x<199; x++)
{
for (y=0; y<199; y++)
{
for (z=0; z<199; z++)
{
vArray[x+y*200+z*200*200] = 123456789;
}
}
}
Tick2 = GetTickCount();
Interval = Tick2 - Tick1;
printf("%d\n", Interval );
Tick1 = GetTickCount();
for (x=0; x<199; x++)
{
for (y=0; y<199; y++)
{
for (z=0; z<199; z++)
{
vArray[x*200*200+y*200+z] = 123456789;
}
}
}
Tick2 = GetTickCount();
Interval = Tick2 - Tick1;
printf("%d\n", Interval );

// oopsy little mistake:
free( vArray );

// has to be, just like in my old code:
delete []vArray;

^^^
probably more safe... ;)
 
R

Richard Heathfield

Skybuck Flying said:
This code nicely demonstrates the different access times for RAM chips
depending on index order/memory layout <- which is much more clear in my
equally competent delphi code.

No, the code demonstrates something all right, but it isn't what you
imagine. And you claim your Delphi code is "equally competent"? I don't
quite know what to say.

P.S.: I love the freedom of speech HAHAHA.

Freedom of speech isn't what you think it is, either.
 
S

Skybuck Flying

Oh now that I do have a working C/C++ example it's interesting to mention
that the slowest code below is even 2.5+ times slower than the Delphi
equivalent.

Hahahahaha at Visual Studio .NET 2003 and all users... oh wait it was the
debug version...

Holyshit, the release version is even 3 times a slow as the delphi debug
equivalent... tut tut tut.

Aren't release version supposed to be FASTER instead of SLOWER LOL.

Needless to say I am so glad I dont program in C++ nor do I use Visual
Studio C++ on a regular bases.

I only use it mostly to compare against Delphi and to have a laugh at C++
and Studio =D

However writing C++ code does have a hi-tech feeling too it but it's not
high tech at all, it's fast, but it's cheap, lazy, nasty, not robust, it s
crap LOL.

It does matter if you use Linux or Knoppix or Windows it s both written in a
CRAP language and thats why it's CRAP LOL.

Fast CRAP, People like FAST CRAP until it CRASHES LOL.

Bye,
Skybuck.
 
S

Skybuck Flying

Richard Heathfield said:
Skybuck Flying said:


No, the code demonstrates something all right, but it isn't what you
imagine. And you claim your Delphi code is "equally competent"? I don't
quite know what to say.

I suggest you start a new newsgroup:

alt.newsgroup.for.frustrated.c.and.c++.programmers.who.nag.a.lot

As a relaxed Delphi programmer I shall stay out of that newsgroup unless I
want to have a laugh :)

Bye,
Skybuck.
 
R

Richard Heathfield

Skybuck Flying said:
Oh now that I do have a working C/C++ example it's interesting to mention
that the slowest code below is even 2.5+ times slower than the Delphi
equivalent.

So write it properly, then.
Hahahahaha at Visual Studio .NET 2003 and all users... oh wait it was the
debug version...

Holyshit, the release version is even 3 times a slow as the delphi debug
equivalent... tut tut tut.

Aren't release version supposed to be FASTER instead of SLOWER LOL.

Not necessarily, when written incompetently.
Needless to say I am so glad I dont program in C++ nor do I use Visual
Studio C++ on a regular bases.

It shows.
 
S

Skybuck Flying

Richard Heathfield said:
Skybuck Flying said:


So write it properly, then.

I did.
Not necessarily, when written incompetently.

Oh, can you write a better example ? I think not.

You simply have a big mouth and have absolutely no clue how to write multi
dimensional code in any language ;)
It shows.

You have shown nothing but insults, big mouths, bad mouths and absolutety
nothing but stinking air.

To an objective reader of this thread it's clear who's the real troll...

It's you
Mister.I.Don't.Know.Jack.Squat.About.Writing.Multi.Dimensional.C.or.C++.Code.Thus.I.Can't.Post.Any.Code.Even.If.I.Wanted.Too.Thus.Therefore.I.Post.Hot.Stinking.Air.And.Bow.To.Might.Skybuck.Proven.Code.

LOL

Bye,
Skybuck.
 
S

Skybuck Flying

Skybuck Flying said:
I did.


Oh, can you write a better example ? I think not.

You simply have a big mouth and have absolutely no clue how to write multi
dimensional code in any language ;)


You have shown nothing but insults, big mouths, bad mouths and absolutety
nothing but stinking air.

To an objective reader of this thread it's clear who's the real troll...

It's you
Mister.I.Don't.Know.Jack.Squat.About.Writing.Multi.Dimensional.C.or.C++.Code.Thus.I.Can't.Post.Any.Code.Even.If.I.Wanted.Too.Thus.Therefore.I.Post.Hot.Stinking.Air.And.Bow.To.Might.Skybuck.Proven.Code.

Let there be no doubt about it, it's MIGHTY Skybuck proven code, typo
corrected !: ;)

You are:

Mister.I.Don't.Know.Jack.Squat.About.Writing.Multi.Dimensional.C.or.C++.Code.Thus.I.Can't.Post.Any.Code.Even.If.I.Wanted.Too.Thus.Therefore.I.Post.Hot.Stinking.Air.And.Bow.To.MIGHTY.Skybuck.Proven.Code.

HAHAHAHA =D

Bye,
A fabolious having day Skybuck hahaha =D
 
S

Skybuck Flying

Hmm I just noticed something...

The loops are incorrected translated..

It could either be:

<200

or

<= 199

I havent coded in a while, havent slept in a while and this code is just
some lazy code to test something ;)

Hehehehe too funny.

It's still amazing to see this 32 MB array assignment in less than 50 or 20
milliseconds...

So I have increased the example to 300x300x300 and that's when I noticed the
incorrect translation...

I might even increase it further for more testing purposes =D

Bye,
Skybuck.
 
S

Skybuck Flying

It turns out this code/concept is quite interesting and possibly quite good
at testing the memory performance in worst and best case scenerio.. at least
for arrays ;)

Amazing to see my system slice through a 256 MB array in less than 500
milliseconds.

It scales lineair too probably... 500.000.000 bytes (not 512 MB but close)
891 milliseconds in debug mode for christ sakes =D lovely.

Finally I got see this piece of system in ACTION =D

LOL is it actually write anything to memory I think so.. but this is
fricking unbelievable fast maybe the constant value has something to do with
it.. but it dont think so...

This system is supposed to even achieve gigabytes of throughput...

Seeing close to 512 MB go through the system in less than one second is
nice....

Now I do have a mathetically/programming question:

I want to create a 3D Cube of integers which uses exactly 512 Megabytes.

512 MB / 4 = 134217728 integers.

Which number can be multiplied by itself three times to achieve 134217728 ?

My math is rusty always been rusty... :)

Il have to think about this one... maybe something with LOG / logarithms or
something ;)

Bye,
Skybuck.
 
S

Skybuck Flying

Now I do have a mathetically/programming question:
I want to create a 3D Cube of integers which uses exactly 512 Megabytes.

512 MB / 4 = 134217728 integers.

Which number can be multiplied by itself three times to achieve 134217728
?

My math is rusty always been rusty... :)

Il have to think about this one... maybe something with LOG / logarithms
or something ;)

Oh well I just cheated.. not sure if it's cheating... I simply used:

134217728 to the power of 0.3333333 (1/3)

Because the outcome is the same as the reverse

outcome to the power of 3

Outcome was 511.+

I ll just use 511.

890 milliseconds for 533.731.324 bytes

512 MB = 536870912

536870912 - 533731324 = 3.139.588

Still almost 3 MB missing.. so that's about 509 MB in 890 milliseconds...

Yeah lol, I love it

Bye,
Skybuck =D
 
T

Tom St Denis

Skybuck said:
Prove me wrong ?

As long as you don't I am the one really laughing my ass off =D

Feeding the troll...

you ever think the compiler/compiler options could be to blame?

GCC with "-O3 -fomit-frame-pointer" on an x86_64 box produced the
following asm from this C source

void blah(int *n)
{
int x, y, z;

for (x = 0; x < 200; x++)
for (y = 0; y < 200; y++)
for (z = 0; z < 200; z++) n[x*200*200 + y *200 + z] = x+y+z;
}

.type blah, @function
blah:
..LFB2:
xorl %r10d, %r10d
..L2:
movl %r10d, %r9d
movq %rdi, %r8
xorl %esi, %esi
.p2align 4,,7
..L5:
leal (%r9,%rsi), %edx
movq %r8, %rcx
xorl %eax, %eax
.p2align 4,,7
..L3:
addl $1, %eax
movl %edx, (%rcx)
addq $4, %rcx
addl $1, %edx
cmpl $200, %eax
jne .L3
addq $1, %rsi
addq $800, %r8
cmpq $200, %rsi
jne .L5
addq $1, %r10
addq $160000, %rdi
cmpq $200, %r10
jne .L2
ret

(I purposefully turned off loop unrolling to show what GCC did).

In this case, GCC removed the multiplications and did simple additions
to get the correct offsets. My bet is MSVC is not doing that, instead
they are doing three IMULs per iteration and hence the slowness.

Hint: GCC basically correctly produces the optimal code for this and
Delphi won't do any better.

Case closed, move on.

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top