From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.user Subject: Re: packed structures usefulness Date: Sat, 03 Nov 2007 10:43:02 +0000 Message-ID: <87ir4jvccp.fsf@ossau.uklinux.net> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1194086604 30040 80.91.229.12 (3 Nov 2007 10:43:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 3 Nov 2007 10:43:24 +0000 (UTC) Cc: guile-user To: "Marco Maggi" Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Nov 03 11:43:28 2007 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IoGTO-0003Nu-OU for guile-user@m.gmane.org; Sat, 03 Nov 2007 11:43:27 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IoGTE-0003v1-EW for guile-user@m.gmane.org; Sat, 03 Nov 2007 06:43:16 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IoGT9-0003ui-NQ for guile-user@gnu.org; Sat, 03 Nov 2007 06:43:11 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IoGT6-0003uQ-UF for guile-user@gnu.org; Sat, 03 Nov 2007 06:43:11 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IoGT6-0003uN-OE for guile-user@gnu.org; Sat, 03 Nov 2007 06:43:08 -0400 Original-Received: from mail3.uklinux.net ([80.84.72.33]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IoGT6-0002St-5W for guile-user@gnu.org; Sat, 03 Nov 2007 06:43:08 -0400 Original-Received: from arudy (host86-145-183-175.range86-145.btcentralplus.com [86.145.183.175]) by mail3.uklinux.net (Postfix) with ESMTP id DBBFC1F6724; Sat, 3 Nov 2007 10:43:03 +0000 (GMT) Original-Received: from laruns (unknown [192.168.0.10]) by arudy (Postfix) with ESMTP id 467A538009; Sat, 3 Nov 2007 10:43:03 +0000 (GMT) In-Reply-To: (Marco Maggi's message of "Fri, 2 Nov 2007 09:12:05 +0100") User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6256 Archived-At: "Marco Maggi" writes: > one can define a SMOB whose internal > representation is equivalent to the C language > type: > > struct triplet { > int one; > double two; > int64_t three[3]; > }; I implemented something like this for an application whose basic control mechanism is message passing using flat C structures ("flat" => no pointers), because I wanted to be able to build and manipulate the structures from Scheme. I handled the padding issue by autogenerating structure definitions like this (from the header files that define the structures): struct struct_desc triplet_desc[] = { { "one", offsetof(struct triplet, one), sizeof(one) }, { "two", offsetof(struct triplet, two), sizeof(two) }, ... }; (It was more complex than shown here, to handle embedded structures, array fields, etc., but I'm sure you get the idea.) Then writing C code to read these definitions and export them to the Scheme level. I didn't use SMOBs. On the Scheme level the structure is just a uniform byte array, and there are procedures for reading and writing fields (identified by name), using the structure definition information. So to answer your actual question: yes, I think this is useful, but only in a rather specific kind of application context. (One could also consider using this approach for reading and writing binary network protocols, but that feels less robust to me than the traditional approach of reading and writing a sequential byte stream.) Regards, Neil _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user