all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ken Raeburn <raeburn@raeburn.org>
To: Stephen J. Turnbull <stephen@xemacs.org>
Cc: Qiang Guo <qguo@ualberta.ca>, emacs-devel@gnu.org
Subject: Re: Quesition about Lisp_Vector
Date: Sat, 12 Nov 2011 20:02:10 -0500	[thread overview]
Message-ID: <32F6D3E9-2729-4F39-8F5D-4604DDF829AB@raeburn.org> (raw)
In-Reply-To: <87ty6aj9al.fsf@uwakimon.sk.tsukuba.ac.jp>

On Nov 11, 2011, at 22:42, Stephen J. Turnbull wrote:
>> a long time, and it works on most if not all C compilers.
> 
> clang (llvm) warns about accesses with a constant index greater than
> zero, but it works.

Good point.  In terms of complaints, I was thinking more about the detection of run-time indexes greater than zero.  I've used one implementation that either interpreted C or compiled with extensive run-time checks (not that it matters which), that probably would've flagged the reference at run time for checking, but I don't recall for sure.  (It was a couple decades ago.)  I expect something like valgrind wouldn't have enough information to detect it.

> Ah, now that interests me.  If there actually is such space, most
> constant index accesses are to a[1], and in theory we could allocate
> array space to fill out the padding.  However, since the structure
> alignment requirement is usually no more than sizeof(pointer), which
> is the same as sizeof(Lisp_Object), and IIRC all of the Lisp_Vectors
> warned about are general (ie, the elements are Lisp_Objects), we
> probably don't buy anything.

Right, in practice in this case it's not likely to save us anything on most platforms.  But an implementation could have rules like "structures over 8 bytes get 16-byte alignment" (assuming 32-bit pointers), in which case there would be wasted space at the end.  On the other hand, the rules could also say that larger arrays get stricter alignment, which (in other use cases, probably not this one) could cause an attempt to utilize that extra space to instead introduce padding before the array.

The C99 spec for flexible array members is even written to give the implementation some flexibility regarding this; it can place the member as if it has some unspecified size chosen by the implementation, with the alignment and padding rules following from that choice.

> I wonder if there is any real loss to allocating two or three elements
> in the base structure (ie, how often vectors of length less than three
> or four are used).

Instrumenting the GC code would be an easy way to find out how many are live at any given GC point, assuming the size fields don't lie.

Ken


      parent reply	other threads:[~2011-11-13  1:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-11  6:29 Quesition about Lisp_Vector Qiang Guo
2011-11-11  8:59 ` Andreas Schwab
2011-11-11  9:01 ` Ken Raeburn
2011-11-12  3:42   ` Stephen J. Turnbull
2011-11-12  8:49     ` Eli Zaretskii
2011-11-12 15:45       ` Stephen J. Turnbull
2011-11-12 15:53         ` Eli Zaretskii
2011-11-13  1:02     ` Ken Raeburn [this message]

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

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

  git send-email \
    --in-reply-to=32F6D3E9-2729-4F39-8F5D-4604DDF829AB@raeburn.org \
    --to=raeburn@raeburn.org \
    --cc=emacs-devel@gnu.org \
    --cc=qguo@ualberta.ca \
    --cc=stephen@xemacs.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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.