Re: Struct is slow



Just wanted to follow-up so people don't think there might be problems
with the Struct class. It isn't actually slow at all. The problem was
just that an inner loop was not converted from an array and so didn't
work and used a lot of CPU resources. Once fixed, I can't tell any
difference between the two versions.

It was this:

type_arr.each do |td_type, td_name|
if t == td_name then
primary_t = td_type
break
end
end

needed to be converted to this:

type_arr.each do |x|
if t == x.typedef_name then
primary_t = x.typedef_type
break
end
end

I used a different naming scheme in that loop (td_name instead of
typedef_name) which caused me not to find it when doing a search for all
places that needed to be converted to a struct.

This is one example where strong typing could have made a difference.
Had the array been declared as an array of arrays or array of structs,
perhaps another language could have detected the error. I'm not
advocating for strongly typed languages, I'm just saying that some kinds
of errors could be harder to find in Ruby. What do you folks think?
--
Posted via http://www.ruby-forum.com/.

.



Relevant Pages

  • Re: Passing an array of structuresfrom a pointer?
    ... to only declare structs in headers and then define the ... the struct should be declared ... what if you have a simple array like this: ... In the header we would declare? ...
    (microsoft.public.vc.language)
  • Re: Passing an array of structuresfrom a pointer?
    ... I've tried an attempt to do that, and I tried to "clean" the header and main ..c file. ... int LIST_NUMBER; ... typedef struct ddListBox{ ... DDLB_COLL1array! ...
    (microsoft.public.vc.language)
  • Re: Marshalling Question: Array of Complex Structs?
    ... I've used no managed types within the struct. ... the following is the code used to call the DLL function. ... C style arrays don't have any information about the length of the array, ... byte buffers to fill with character data while the marshalling code ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: LONG: Variable internals and copy-on-write
    ... mxArray structure than ... struct mxArray_tag { ... int vartype; ... The header of a cell array looks identical to the ...
    (comp.soft-sys.matlab)
  • Re: Passing an array of structuresfrom a pointer?
    ... I just tried to access data from the DDLB_COLL1 array and got an error! ... int LIST_NUMBER; ... typedef struct ddListBox{ ... to only declare structs in headers and then define the ...
    (microsoft.public.vc.language)