Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 6, 2013, 05:42 AM   #1
farmerdoug
macrumors 6502a
 
Join Date: Sep 2008
memset? Please look

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));
farmerdoug is offline   0 Reply With Quote
Old Jun 6, 2013, 07:23 AM   #2
cqexbesd
macrumors member
 
Join Date: Jun 2009
Quote:
Originally Posted by farmerdoug View Post
What did I do wrong?
Not provide the error message? Or maybe not provide a small compilable example? ;-)

Andrew
cqexbesd is offline   0 Reply With Quote
Old Jun 6, 2013, 07:34 AM   #3
farmerdoug
Thread Starter
macrumors 6502a
 
Join Date: Sep 2008
Its a EXC_BAD_ACCESS error. A problem with memory allocation. You gave me a clue. Have to check things.
farmerdoug is offline   0 Reply With Quote
Old Jun 6, 2013, 09:34 AM   #4
subsonix
macrumors 68030
 
Join Date: Feb 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.

For example, allocating 100 items of size int would give: 100^5 * 4 = 40 gigabytes.
subsonix is offline   0 Reply With Quote
Old Jun 6, 2013, 10:42 AM   #5
farmerdoug
Thread Starter
macrumors 6502a
 
Join Date: Sep 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.
Thanks.
farmerdoug is offline   0 Reply With Quote
Old Jun 6, 2013, 02:33 PM   #6
Sander
macrumors 6502
 
Join Date: Apr 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...
Sander is offline   1 Reply With Quote
Old Jun 7, 2013, 08:51 AM   #7
robvas
macrumors 68000
 
Join Date: Mar 2009
Location: USA
Quote:
Originally Posted by Sander View Post
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...
robvas is offline   0 Reply With Quote
Old Jun 7, 2013, 10:27 PM   #8
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
I think some typedefs are called for... So that you don't have to write ***** repeatedly (looks like I have censored profanity, hah.)
ArtOfWarfare is offline   0 Reply With Quote
Old Jun 8, 2013, 11:03 AM   #9
subsonix
macrumors 68030
 
Join Date: Feb 2008
Most likely it could also be done with a struct and a one dimensional array.
subsonix is offline   0 Reply With Quote
Old Jun 8, 2013, 05:35 PM   #10
Mr. Retrofire
macrumors 601
 
Mr. Retrofire's Avatar
 
Join Date: Mar 2010
Location: www.emiliana.cl
Quote:
Originally Posted by subsonix View Post
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.
__________________

“Only the dead have seen the end of the war.”
-- Plato --
Mr. Retrofire is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump

All times are GMT -5. The time now is 11:38 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC