memset? Please look

Discussion in 'Mac Programming' started by farmerdoug, Jun 6, 2013.

  1. macrumors 6502a

    Sep 16, 2008
    memset gives an error. What did I do wrong? When signal was *signal, I didn't get an error. As near as I can tell, I am still sending a 1-D array to find_breakouts. thanks

    int  *****signal
    signal = (int*****) calloc (number_of_vols, sizeof(int****));
    		for (i = 0; i < number_of_vols; i++)
    			signal[i] = (int****) calloc (number_of_vols, sizeof(int ***));
    			for (j = 0; j < number_of_vols; j++)
    				signal[i][j] = (int***) calloc (num_buy_channels, sizeof(int **));
    				for (k = 0; k < num_buy_channels; k++)
    					signal[i][j][k] = (int**) calloc (num_sell_channels, sizeof(int *));
    					for (l = 0; l < num_sell_channels; l++)
    						signal[i][j][k][l] = (int*) calloc (days_of_data, sizeof(int ));
    find_breakouts(sauce, signal[vol1][vol2][buy_channel][sell_channel],buy_count, sell_count, date_list);
    void find_breakouts( float* sauce,  int * sign, int buy_count, int sell_count, char ** date_list)
    	int i, j;
    	int  search, end;
    	memset(sign, 0, days_of_data*sizeof(int));
  2. macrumors member

    Jun 4, 2009
    Not provide the error message? Or maybe not provide a small compilable example? ;-)

  3. thread starter macrumors 6502a

    Sep 16, 2008
    Its a EXC_BAD_ACCESS error. A problem with memory allocation. You gave me a clue. Have to check things.
  4. macrumors 68040

    Feb 2, 2008
    How much do you allocate in each dimension? You never check the return value of calloc and it's not unlikely that you ran out of memory. :D

    For example, allocating 100 items of size int would give: 100^5 * 4 = 40 gigabytes.
  5. thread starter macrumors 6502a

    Sep 16, 2008
    I added a check and yes I wasn't running out of memory. What I was doing was over stepping the memory by using the wrong variables in for the indicies.
  6. macrumors 6502

    Apr 24, 2008
    OK, this is not much of a useful post but I just thought it was amusing that I opened this thread, saw the first line of code with a 5-fold-nested pointer, and I immediately knew who posted this thread without seeing the name of the submitter yet.

    Farmerdoug, I wonder whether the complexity of the stuff you're trying to do wouldn't warrant you investing some time in a higher-level language...
  7. macrumors 68000

    Mar 29, 2009
    Been telling him that for years...
  8. macrumors 604


    Nov 26, 2007
    I think some typedefs are called for... So that you don't have to write ***** repeatedly (looks like I have censored profanity, hah.)
  9. macrumors 68040

    Feb 2, 2008
    Most likely it could also be done with a struct and a one dimensional array.
  10. macrumors 601

    Mr. Retrofire

    Mar 2, 2010
    iAgree™. The complexity is utterly unnecessary, and causes probably more problems, than it solves.

Share This Page