multi dimensional array example

Discussion in 'C++' started by Skybuck Flying, Nov 24, 2006.

  1. 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.
     
    Skybuck Flying, Nov 24, 2006
    #1
    1. Advertising

  2. 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.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at the above domain, - www.
     
    Richard Heathfield, Nov 24, 2006
    #2
    1. Advertising

  3. "Richard Heathfield" <> wrote in message
    news:...
    > 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.


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

    Bye,
    Skybuck.
     
    Skybuck Flying, Nov 24, 2006
    #3
  4. Skybuck Flying said:

    >
    > "Richard Heathfield" <> wrote in message
    > news:...
    >> 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.

    >
    > 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.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at the above domain, - www.
     
    Richard Heathfield, Nov 24, 2006
    #4
  5. "Skybuck Flying" <> wrote in message
    news:ek6kip$pv3$1.ov.home.nl...
    > 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... ;)

    > getchar();
    > return 0;
    > }
    >
    > Gosh I even had to boot up my old pentium III 450 mhz computer to consult
    > my old C/C++ code.
    >
    > I really should transfer that stuff to my new Dream PC some day LOL.
    >
    > To avoid such nagging fools like this **** face in the previous post LOL.
    >
    > Bye,
    > Skybuck.
    >
    > P.S.: I love the freedom of speech HAHAHA.
    >
     
    Skybuck Flying, Nov 24, 2006
    #5
  6. 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.

    <snip>

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


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

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at the above domain, - www.
     
    Richard Heathfield, Nov 24, 2006
    #6
  7. 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.
     
    Skybuck Flying, Nov 24, 2006
    #7
  8. "Richard Heathfield" <> wrote in message
    news:...
    > 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.


    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.
     
    Skybuck Flying, Nov 24, 2006
    #8
  9. 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.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at the above domain, - www.
     
    Richard Heathfield, Nov 24, 2006
    #9
  10. "Richard Heathfield" <> wrote in message
    news:...
    > 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.


    I did.

    >> 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.


    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 ;)

    >
    >> 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.


    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.
     
    Skybuck Flying, Nov 24, 2006
    #10
  11. "Skybuck Flying" <> wrote in message
    news:ek6rn6$bj7$1.ov.home.nl...
    > "Richard Heathfield" <> wrote in message
    > news:...
    >> 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.

    >
    > I did.
    >
    >>> 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.

    >
    > 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 ;)
    >
    >>
    >>> 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.

    >
    > 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
     
    Skybuck Flying, Nov 24, 2006
    #11
  12. 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.


    "Skybuck Flying" <> wrote in message
    news:ek6kip$pv3$1.ov.home.nl...
    > 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 );
    > free( vArray );
    > getchar();
    > return 0;
    > }
    >
    > Gosh I even had to boot up my old pentium III 450 mhz computer to consult
    > my old C/C++ code.
    >
    > I really should transfer that stuff to my new Dream PC some day LOL.
    >
    > To avoid such nagging fools like this **** face in the previous post LOL.
    >
    > Bye,
    > Skybuck.
    >
    > P.S.: I love the freedom of speech HAHAHA.
    >
     
    Skybuck Flying, Nov 24, 2006
    #12
  13. Skybuck Flying said:

    > "Richard Heathfield" <> wrote in message
    > news:...
    >> 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.

    >
    > I did.


    ROTFL!

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at the above domain, - www.
     
    Richard Heathfield, Nov 24, 2006
    #13
  14. 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.
     
    Skybuck Flying, Nov 24, 2006
    #14
  15. > 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
     
    Skybuck Flying, Nov 24, 2006
    #15
  16. Skybuck Flying

    Jim Langston Guest

    "Skybuck Flying" <> wrote in message
    news:ek6kip$pv3$1.ov.home.nl...
    > First I stick my big ...


    *PLOINK*
     
    Jim Langston, Nov 24, 2006
    #16
  17. "Richard Heathfield" <> wrote in message
    news:...
    > Skybuck Flying said:
    >
    >> "Richard Heathfield" <> wrote in message
    >> news:...
    >>> 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.

    >>
    >> I did.

    >
    > ROTFL!


    Prove me wrong ?

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

    Bye,
    Skybuck.
     
    Skybuck Flying, Nov 24, 2006
    #17
  18. "Jim Langston" <> wrote in message
    news:RTB9h.329$...
    >
    > "Skybuck Flying" <> wrote in message
    > news:ek6kip$pv3$1.ov.home.nl...
    >> First I stick my big ...

    >
    > *PLOINK*


    Ok my turn:

    PLOEP hahaha
     
    Skybuck Flying, Nov 24, 2006
    #18
  19. Skybuck Flying

    Tom St Denis Guest

    Skybuck Flying wrote:
    > > ROTFL!

    >
    > 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
     
    Tom St Denis, Nov 24, 2006
    #19
  20. Skybuck Flying wrote:

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


    512^3 = 134217728

    --
    Behold, we know not anything;
    I can but trust that good shall fall
    At last--far off--at last, to all,
    And every winter change to spring.
     
    Frederick Williams, Nov 24, 2006
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kk_oop
    Replies:
    1
    Views:
    2,166
  2. Venkat
    Replies:
    4
    Views:
    975
    Venkat
    Dec 5, 2003
  3. ian douglas
    Replies:
    2
    Views:
    987
    Randy Howard
    Jul 30, 2004
  4. Skybuck Flying

    multi dimensional array example

    Skybuck Flying, Nov 24, 2006, in forum: C Programming
    Replies:
    44
    Views:
    1,185
    Skybuck Flying
    Nov 30, 2006
  5. Wirianto Djunaidi
    Replies:
    2
    Views:
    203
    Wirianto Djunaidi
    Apr 29, 2008
Loading...

Share This Page