RE: Handling Structured Memory
- Posted by Don Phillips <EuNexus at yahoo.com> Nov 13, 2002
- 418 views
> Yes, strings are slower to search than integers, but I've never noticed > a difference. Also if I were concerned with speed, I would use David > Cuny's c-structure library. It's about as fast as yer gonna wrapr > c-struct manipulation, without just doing it all manually, at low level. > > But I've always had a difficult time using it, so I prefer the slower > method. I've never had a problem. There are numerous quite a few > projects that have used structs.e. Thats Euphoria at work =) Just make it work, Euphoria will worry about the speed :P > The use of strings was a choice, in order to allow easily nested > structures, and a matter of readability, and the definitely lack of > need, for excess constants. > > Integers are also used, for nested structs. > > And a structure definition is only ever created once, and then > referenced. Whatever size is spent on the definition is minimal. Yeah same here... > I haven't seen your lib, so I can only speculate, but I assume, that > your structs must be accessed at each nesting level, instead of directly > > with one call. Actually that assumption is incorrect... > structs.e allows you to do this.. > ---------------- > constant NAME = define_c_struct({ > {"fname", LPSTR, 1}, > {"lname", LPSTR, 4} > }) > > constant CLIENT = define_c_struct({ > {"id", LONG, 1}, > {"name", NAME, 1} > }) > > atom client client = alloc_struct(CLIENT) > poke_struct(client,{"name","fname"},poke_string("Fred")) > > ---------------- > It's definitely slower than some of the other solutions, but it's a > rounded solution. > > Chris constant X = define_member(), Y = define_member(), P1 = define_member(), P2 = define_member() constant POINT = define_struct({ { X, DWORD, 1 }, { Y, DWORD, 1 } }) constant RECT = define_struct({ { P1, POINT, 1 }, { P2, POINT, 1 } }) constant NAME = define_struct({ { X, BYTE, 50 } <<-- X used twice }) constant Point = struct(POINT) constant Rect = struct(RECT) constant Name = struct(NAME) struct_set( Point, X, 10 } struct_set( Rect, {P1,Y}, 6 ) struct_set( Name, X, "Fred" ) ... Don