memset? Please look

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

  1. macrumors 6502a

    Joined:
    Sep 16, 2008
    #1
    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

    Code:
    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

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

    Andrew
     
  3. thread starter macrumors 6502a

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

    Joined:
    Feb 2, 2008
    #4
    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

    Joined:
    Sep 16, 2008
    #5
    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.
    Thanks.
     
  6. macrumors 6502

    Joined:
    Apr 24, 2008
    #6
    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

    Joined:
    Mar 29, 2009
    Location:
    USA
    #7
    Been telling him that for years...
     
  8. macrumors 603

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #8
    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

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

    Mr. Retrofire

    Joined:
    Mar 2, 2010
    Location:
    www.emiliana.cl
    #10
    iAgree™. The complexity is utterly unnecessary, and causes probably more problems, than it solves.
     

Share This Page