unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Jean Abou Samra <jean@abou-samra.fr>
To: Walter Lewis <wklew@mailbox.org>, guile-user@gnu.org, arne_bab@web.de
Subject: Re: Breaking hygiene with syntax-rules?
Date: Sat, 12 Aug 2023 02:58:21 +0200	[thread overview]
Message-ID: <e9e9865294e1e0460f768b75ce540a5025249d6d.camel@abou-samra.fr> (raw)
In-Reply-To: <e2e74674-7a2d-543d-16e9-27707bff2f90@mailbox.org>

[-- Attachment #1: Type: text/plain, Size: 2131 bytes --]

Le vendredi 11 août 2023 à 20:19 -0400, Walter Lewis a écrit :
> To be honest I don't know enough about C to know the performance of 
> bytevector->pointer, so I was assuming Chickadee's approach was done for 
> a reason.


Below is the definition of bytevector->pointer in libguile/foreign.c:


SCM_DEFINE (scm_bytevector_to_pointer, "bytevector->pointer", 1, 1, 0,
	    (SCM bv, SCM offset),
	    "Return a pointer pointer aliasing the memory pointed to by\n"
            "@var{bv} or @var{offset} bytes after @var{bv} when @var{offset}\n"
	    "is passed.")
#define FUNC_NAME s_scm_bytevector_to_pointer
{
  SCM ret;
  signed char *ptr;
  size_t boffset;

  SCM_VALIDATE_BYTEVECTOR (1, bv);
  ptr = SCM_BYTEVECTOR_CONTENTS (bv);

  if (SCM_UNBNDP (offset))
    boffset = 0;
  else
    boffset = scm_to_unsigned_integer (offset, 0,
                                       SCM_BYTEVECTOR_LENGTH (bv) - 1);

  ret = scm_from_pointer (ptr + boffset, NULL);
  register_weak_reference (ret, bv);
  return ret;
}
#undef FUNC_NAME


In plain English, this is basically just checking that the first argument
is a bytevector and the second argument (if provided, defaults to 0)
is an integer that is in bounds for the bytevector, then it calls


SCM
scm_from_pointer (void *ptr, scm_t_pointer_finalizer finalizer)
{
  SCM ret;

  if (ptr == NULL && finalizer == NULL)
    ret = null_pointer;
  else
    {
      ret = scm_cell (scm_tc7_pointer, (scm_t_bits) ptr);

      if (finalizer)
        scm_i_set_finalizer (SCM2PTR (ret), pointer_finalizer_trampoline,
                             finalizer);
    }

  return ret;
}


which just wraps the pointer into a (small and cheap) Guile object,
and that's basically it. So, yet, it's very cheap.

The only possible cost that I can see is memory and GC footprint,
e.g., it's like creating many SRFI-111 boxes to the same object
vs. one box, that kind of overhead. The objects themselves are
very lightweight. You would really have to go out of your way and
create an awful lot of them for this to make any difference.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2023-08-12  0:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-11  2:35 Breaking hygiene with syntax-rules? Walter Lewis via General Guile related discussions
2023-08-11  5:07 ` Dr. Arne Babenhauserheide
2023-08-11  8:00 ` Jean Abou Samra
2023-08-11  8:33   ` Dr. Arne Babenhauserheide
2023-08-11 23:57     ` Jean Abou Samra
2023-08-12  5:57       ` Dr. Arne Babenhauserheide
2023-08-11 13:34   ` Walter Lewis via General Guile related discussions
2023-08-11 22:50     ` Walter Lewis via General Guile related discussions
2023-08-11 23:55       ` Jean Abou Samra
2023-08-11 23:57         ` Jean Abou Samra
2023-08-12  0:19           ` Walter Lewis
2023-08-12  0:58             ` Jean Abou Samra [this message]
2023-08-12  5:59             ` Dr. Arne Babenhauserheide
2023-08-14 19:26               ` Thompson, David

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e9e9865294e1e0460f768b75ce540a5025249d6d.camel@abou-samra.fr \
    --to=jean@abou-samra.fr \
    --cc=arne_bab@web.de \
    --cc=guile-user@gnu.org \
    --cc=wklew@mailbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).