I think that's what he's asking; How is it done in C/C++. If your code accesses the memory I'd be surprised if the compiler just deallocates it. I've never seen that and would be rather pissed off if my compiler decided to break my code by 'optimising' away memory that I'd need to access. What settings would allow that?camsr wrote:The same way as any other C/C++ constant. Make sure the compilation settings don't remove it either.
Easy C++ Questions
-
- KVRian
- 1273 posts since 9 Jan, 2006
-
- KVRAF
- 7402 posts since 17 Feb, 2005
It depends if they are "used" or not. In GCC, IIRC it's Dead Code Removal. If it's referenced by an ambiguous pointer, that might make it seem unused.
If he is writing the values to memory using new, they should be there.
If he is writing the values to memory using new, they should be there.
-
- KVRian
- 1273 posts since 9 Jan, 2006
I'm aware of dead code removal, but I've never ran into a situation of pointer ambiguity causing this problem. Are you talking about user error, or the compiler not being smart enough to resolve the pointer at compile time? Either way this is going a little OT
EXC_BAD_ACCESS could also result from accessing outside of array bounds (0 to n-1).
EXC_BAD_ACCESS could also result from accessing outside of array bounds (0 to n-1).
-
- KVRian
- 1379 posts since 26 Apr, 2004 from UK
I would definitely advise to start by the basics, and obviously you are not there yet. Not try to get too far ahead without mastering the fundamentals of the language.
- KVRAF
- Topic Starter
- 2245 posts since 25 Sep, 2014 from Specific Northwest
Here's what I've got:
In header:
In Constructor:
In process(...):
In Crash Report:
n0 through n4 are all ints calculated cyclically from 0-1023 and are defined with int index and float s just before the loop, so are valid(ish).
That was part of an inline call to an interpolation method, but I broke it out for troubleshooting. If I bypass it and just calculate s = (float)sin((float)j*PI*2.0f/1023.0f); I get wave sign--er, a sine wave, but it does make a noise.
In header:
Code: Select all
private:
float **wave;
float **coeffs;
Code: Select all
coeffs = new float *[4];
for (int i=0; i<4; i++)
coeffs[i] = new float [128];
makeCoeffs();
wave = new float *[NO_OF_WAVES];
for (int i=0; i<NO_OF_WAVES; i++)
wave[i] = new float [1024];
makeWaves();
Code: Select all
s = (wave[NO_OF_NODES][n0]) * (coeffs[0][index]) + (wave[NO_OF_NODES][n1]) * (coeffs[1][index]) +
(wave[NO_OF_NODES][n2]) * (coeffs[2][index]) + (wave[NO_OF_NODES][n3]) * (coeffs[3][index]);
Code: Select all
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0xffffffff10e3fffc
That was part of an inline call to an interpolation method, but I broke it out for troubleshooting. If I bypass it and just calculate s = (float)sin((float)j*PI*2.0f/1023.0f); I get wave sign--er, a sine wave, but it does make a noise.
Last edited by syntonica on Wed Nov 23, 2016 11:55 am, edited 1 time in total.
I started on Logic 5 with a PowerBook G4 550Mhz. I now have a MacBook Air M1 and it's ~165x faster! So, why is my music not proportionally better?
- KVRAF
- Topic Starter
- 2245 posts since 25 Sep, 2014 from Specific Northwest
I've checked everything I can think of, including compiler settings. Grah!
I started on Logic 5 with a PowerBook G4 550Mhz. I now have a MacBook Air M1 and it's ~165x faster! So, why is my music not proportionally better?
-
- KVRAF
- 2393 posts since 28 Mar, 2005
- KVRAF
- Topic Starter
- 2245 posts since 25 Sep, 2014 from Specific Northwest
Thanks, but the arrays I am using are fixed in size, so I'm not sure what I could gain by this.otristan wrote:use std::vector
I started on Logic 5 with a PowerBook G4 550Mhz. I now have a MacBook Air M1 and it's ~165x faster! So, why is my music not proportionally better?
- KVRAF
- Topic Starter
- 2245 posts since 25 Sep, 2014 from Specific Northwest
I'm using Xcode, so it's probably doing quite a number of "nice" things for me that I'm unaware of, making debugging a much harder task than it should be. Divide by zero? Don't worry... we'll make that go away for you...matt42 wrote:I think that's what he's asking; How is it done in C/C++. If your code accesses the memory I'd be surprised if the compiler just deallocates it. I've never seen that and would be rather pissed off if my compiler decided to break my code by 'optimising' away memory that I'd need to access. What settings would allow that?camsr wrote:The same way as any other C/C++ constant. Make sure the compilation settings don't remove it either.
I started on Logic 5 with a PowerBook G4 550Mhz. I now have a MacBook Air M1 and it's ~165x faster! So, why is my music not proportionally better?
- KVRAF
- Topic Starter
- 2245 posts since 25 Sep, 2014 from Specific Northwest
NO_OF_NODES is a #define.matt42 wrote:What is no_of_nodes? What is index set to? How are/are they incremented?
Use a debugger and make sure nothing goes out of bounds. Should be simple enough to verify.
Oh crap... it's my indices. I just replaced them all with hard values and no crash...
...sigh...
Back to the drawing board... Can I go back to Java now?
Sorry for my frustration spilling out onto this board. But having to learn a new IDE (Xcode) AND a new language extension (c++) at the same time is driving me spare. It makes me want to kick a puppy at times.
I started on Logic 5 with a PowerBook G4 550Mhz. I now have a MacBook Air M1 and it's ~165x faster! So, why is my music not proportionally better?
- KVRist
- 347 posts since 20 Apr, 2005 from Moscow, Russian Federation
Aside of the error get use of typedefs, e.g.:
->
etc.
Also counting that NO_OF_NODES is a constant I suspect the NO_OF_WAVES is a (compile time) constant too, if so you could use the array w/o any new/delete at all (same goes for your coeffs array).
Code: Select all
wave = new float *[NO_OF_WAVES];
for (int i=0; i<NO_OF_WAVES; i++)
wave[i] = new float [1024];
Code: Select all
typedef float Wave[1024];
Wave* wave = new Wave[NO_OF_WAVES];
Also counting that NO_OF_NODES is a constant I suspect the NO_OF_WAVES is a (compile time) constant too, if so you could use the array w/o any new/delete at all (same goes for your coeffs array).
- KVRAF
- Topic Starter
- 2245 posts since 25 Sep, 2014 from Specific Northwest
OMG! Thank you so much! I went through every permutation I could find of how to define a new 2D array. That one actually makes sense and works! I had completely forgotten about "typedef".Max M. wrote:Code: Select all
typedef float Wave[1024]; Wave* wave = new Wave[NO_OF_WAVES];
I started on Logic 5 with a PowerBook G4 550Mhz. I now have a MacBook Air M1 and it's ~165x faster! So, why is my music not proportionally better?
-
- KVRAF
- 2393 posts since 28 Mar, 2005
You could as well interleave your data in the same array
way easier and with a better locality.
way easier and with a better locality.
- KVRist
- 347 posts since 20 Apr, 2005 from Moscow, Russian Federation
It can be written w/o a typedef too (if I recall correctly though):syntonica wrote:I went through every permutation I could find of how to define a new 2D array.
Code: Select all
float (*wave)[1024] = new float[NO_OF_WAVES][1024];