PDA

View Full Version : memset? Please look




farmerdoug
Jun 6, 2013, 05:42 AM
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));



cqexbesd
Jun 6, 2013, 07:23 AM
What did I do wrong?

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

Andrew

farmerdoug
Jun 6, 2013, 07:34 AM
Its a EXC_BAD_ACCESS error. A problem with memory allocation. You gave me a clue. Have to check things.

subsonix
Jun 6, 2013, 09:34 AM
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.

farmerdoug
Jun 6, 2013, 10:42 AM
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.

Sander
Jun 6, 2013, 02:33 PM
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...

robvas
Jun 7, 2013, 08:51 AM
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...

Been telling him that for years...

ArtOfWarfare
Jun 7, 2013, 10:27 PM
I think some typedefs are called for... So that you don't have to write ***** repeatedly (looks like I have censored profanity, hah.)

subsonix
Jun 8, 2013, 11:03 AM
Most likely it could also be done with a struct and a one dimensional array.

Mr. Retrofire
Jun 8, 2013, 05:35 PM
Most likely it could also be done with a struct and a one dimensional array.
iAgree™. The complexity is utterly unnecessary, and causes probably more problems, than it solves.