Skydiver's Profile User Rating: ****-

Reputation: 4776 Guru
Group:
Moderators
Active Posts:
15,893 (10.89 per day)
Joined:
05-May 12
Profile Views:
73,629
Last Active:
User is offline Today, 04:24 PM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
AMD
Favorite Gaming Platform:
PC
Your Car:
Toyota
Dream Kudos:
100
Expert In:
C/C++, C#

Latest Visitors

Icon   Skydiver has not set their status

Posts I've Made

  1. In Topic: Returning pointer from a function processing 2D array.

    Posted 3 May 2016

    Consider these two functions:
    int ** Pointer_Func1(int n)
    {
        int ** board = new int *[n];
        for (int i = 0; i < n; i++)
            board[i] = new int[n];
    
        for (int row = 0; row < n; row++)
        {
            for (int col = 0; col < n; col++)
                board[row][col] = row * n + col + 1;
        }
    
        return board;
    }
    
    int ** Pointer_Func2(int n)
    {
        char * buffer = new char[n * (sizeof(int *) + n * sizeof(int))];
        int ** board = reinterpret_cast<int **>(buffer);
        int * data = reinterpret_cast<int *>(buffer + n * sizeof(int *));
        for (int i = 0; i < n; i++)
        {
            board[i] = data;
            data += n;
        }
    
        for (int row = 0; row < n; row++)
        {
            for (int col = 0; col < n; col++)
                board[row][col] = row * n + col + 1;
        }
    
        return board;
    }
    
    


    Although both essentially return an array of pointers of pointers integers, the first allocates the inner pointers as separate blocks, while the second allocates everything in a single block and just points within itself. Your main() function will have to know this internal detail. This does not make for a good design.
  2. In Topic: Returning pointer from a function processing 2D array.

    Posted 3 May 2016

    It is possible to do the clean up outside of the function, but you have to know the details of how the function allocated the memory. This leads to tight coupling which should be avoided. This is the reason why the suggestion was to have a class encapsulate the returned arrray so that class is internally cohesive and knows how to allocate and deallocate on its own.
  3. In Topic: Adding to an array

    Posted 3 May 2016

    You likely want a Dictionary<> rather than an array if you want to use 'strings' to 'index into' a collection. High overhead for the convenience. Learn how to use arrays properly is my recommendation if it's going to be a fixed size list. At worse, use an enum to avoid magic numbers.
  4. In Topic: Timer countdown

    Posted 3 May 2016

    Yup, that was a poorly designed object interface. Properties should not "do stuff". Methods should "do stuff". Probably had an intern working on that class during the .NET Framework 1.1 days. :)
  5. In Topic: Timer countdown

    Posted 3 May 2016

    Did you register for the tick event?

My Information

Member Title:
Code herder
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Interests:
programming, shooting, skydiving, scuba, photography, game dev, cryptography, design patterns, agile methodologies, scifi, fantasy,
Years Programming:
33
Programming Languages:
C, C++. C#, PHP, JavaScript, Pascal, SQL, BASIC, Forth, x86, 65000, 65xx,

Contact Information

E-mail:
Private

Comments

  • (2 Pages)
  • +
  • 1
  • 2
  1. Photo

    moonlight1020 Icon

    07 Jul 2015 - 06:26
    http://www.dreamincode.net/forums/topic/378386-problem-with-char-array/page__st__15__gopid__2167338&#entry2167338
  2. Photo

    tarmizi_adam2005 Icon

    08 Mar 2014 - 09:03
    Congrats on the 3k rep ! also, before your rep changes nice palindrome rep, 3003.
  3. Photo

    tarmizi_adam2005 Icon

    27 Nov 2013 - 18:56
    Just wanted to stop by and say thanks on the advices you gave in my post (read wav files C/C++) the other day.
    Thanks again Skydiver
  4. Photo

    raspinudo Icon

    03 Jul 2013 - 05:51
    Nice Star Trek t.n.g. Reference
  5. Photo

    todddowers Icon

    26 Jun 2013 - 23:07
    hello i was wondering do you know anything about text based games.
  6. Photo

    CY5 Icon

    10 Jun 2013 - 07:07
    Thanks SkyDiver you're always there to help on C# forum
  7. Photo

    Jovel Mark Icon

    05 Mar 2013 - 23:51
    salamat sa pagtulong .. keep it up the work..
    kung wala kamo wala kami mahimo sang amon nga project ba,, madamo gd nga salamat sa pagtabang..
  8. Photo

    tlhIn`toq Icon

    30 Dec 2012 - 16:20
    Congrats on the Mentor badge. I think that is new record. Glad to have you on board.
  9. Photo

    lp94 Icon

    07 Oct 2012 - 06:09
    thank you soooooo much <3
  10. Photo

    kai_itz me Icon

    25 Sep 2012 - 04:40
    i agreed with MrShoes.
    More knowledgeable than many; more patient than most.
    very well said :)
  11. Photo

    tlhIn`toq Icon

    01 Sep 2012 - 15:22
    I just saw the Expert badge... Well done!
  12. Photo

    nazzie Icon

    22 Aug 2012 - 00:34
    Thanks for your Help! Keep up the good work.. thanks so much! ^_^
  13. Photo

    vikuseth Icon

    17 Aug 2012 - 23:12
    hi
    thanks for helping me in Dll issue .
    you are the best. ..
    good luck...
  14. Photo

    MrShoes Icon

    08 Aug 2012 - 00:49
    More knowledgeable than many; more patient than most.
  15. Photo

    BarackObama Icon

    31 Jul 2012 - 00:59
    This guy is the best! Love him
  • (2 Pages)
  • +
  • 1
  • 2