Segmentation fault after having a certain number of elements in an array?

Jeremy DeHaan via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Dec 13 01:43:40 PST 2014


On Saturday, 13 December 2014 at 09:24:51 UTC, Paul wrote:
> On Saturday, 13 December 2014 at 08:59:19 UTC, Jeremy DeHaan 
> wrote:
>
>
>> 	for(int i = 0; i<samples.length; ++i)
>
>> 	m_samples.length +=1;
>
> You are testing i against an ever-increasing limit aren't you, 
> so it's an infinite loop.

Not really. When the function is called, the length of "samples" 
(Incoming sound data) is usually around 4000. "m_samples" (the 
total samples recorded) doesn't make it past 1024 in length 
without segfaulting.

It probably doesn't matter, but the array passed to this function 
is actually a slice created from a pointer and length generated 
in the C++ side.


More information about the Digitalmars-d-learn mailing list