Re: Bug segmentation fault

From: [email protected]

I am trying to display the contents of large array (over 1000 rows)
using arrayName.collect {|x| puts x.inspect}
However the following occurs:

[Bug] Segmentation fault
ruby 1.8.5 (20006-08-25) [i386-mswin32]

I have no idea if it will make a different, but do you realize that by
calling collect you are creating an array whose entries are the return
value of puts (which is always nil). An array of over 1000 nil entries.

I think you probably want either:
arrayName.each{ |x| puts x.inspect }
or
puts arrayName.collect{ |x| x.inspect }

Gavin K. wrote:

value of puts (which is always nil). An array of over 1000 nil entries.

I think you probably want either:
arrayName.each{ |x| puts x.inspect }
or
puts arrayName.collect{ |x| x.inspect }

True, but it shouldn’t segfault in any case. I’m curious what the
objects of arrayName look like. I was not able to duplicate this
problem with a 10000 element array of simple objects.

Regards,

Dan

Daniel B. wrote:

value of puts (which is always nil). An array of over 1000 nil entries.

I think you probably want either:
arrayName.each{ |x| puts x.inspect }
or
puts arrayName.collect{ |x| x.inspect }

This is also a nice alternative to try:

require ‘pp’
pp arrayName

And, btw, in Ruby we conventionally use underscores instead of camelCase
so array_name is preferred. Of course that is a pretty meaningless
identifier so that should probably named differently altogether. :slight_smile:

True, but it shouldn’t segfault in any case. I’m curious what the
objects of arrayName look like. I was not able to duplicate this
problem with a 10000 element array of simple objects.

Yeah, OP what objects do you have in that array? Are you using some
kind of C extension? Is this a recursive data structure?

Regards

robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs