From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Keith David Bershatsky Newsgroups: gmane.emacs.devel Subject: Re: Universal functions to manage multiple window caches. Date: Thu, 18 Apr 2019 18:44:59 -0700 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="7402"; mail-complaints-to="usenet@blaine.gmane.org" Cc: emacs-devel@gnu.org To: Alex Gramiak Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Apr 19 03:45:27 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hHIaj-0001m2-IZ for ged-emacs-devel@m.gmane.org; Fri, 19 Apr 2019 03:45:26 +0200 Original-Received: from localhost ([127.0.0.1]:49837 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hHIai-000393-C9 for ged-emacs-devel@m.gmane.org; Thu, 18 Apr 2019 21:45:24 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:45167) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hHIab-00038u-BJ for emacs-devel@gnu.org; Thu, 18 Apr 2019 21:45:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hHIaY-00041b-LR for emacs-devel@gnu.org; Thu, 18 Apr 2019 21:45:17 -0400 Original-Received: from gateway20.websitewelcome.com ([192.185.70.14]:13821) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hHIaY-0003sz-4b for emacs-devel@gnu.org; Thu, 18 Apr 2019 21:45:14 -0400 Original-Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 9B937400C7B49 for ; Thu, 18 Apr 2019 20:45:00 -0500 (CDT) Original-Received: from gator3053.hostgator.com ([50.87.144.69]) by cmsmtp with SMTP id HIaKhznrs2qH7HIaKhLH7t; Thu, 18 Apr 2019 20:45:00 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lawlist.com ; s=default; h=Content-Type:MIME-Version:Subject:Cc:To:From:Message-ID:Date: Sender:Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=/G2T6mboHR4TTa4DmuuVUl5abqp9qV8ISw8urzPkZ5w=; b=YpF2/BF0x602HYPQY7Z+P8wnCw 35pz70zaHr4NvuGrBVFkA6fRbg/sW3YBX4SHi+AWADcs+J016zjGokQZnpuiCtoQ3LH5tisbe/6GZ k2b00echfmqYEuOq69yQ/UEAgziRjJOqGac+SQaHecqTmgpmVzEDwSePj/VPqvku9ADmZ5bLHvClr Y7Mt8PXcHLb2qtOwU7Axq2yO2CSdga5vZ2H1sELYxDNxqibfk+Vkje1Ix9YuZq1OwKL6zXew/NsHD 6nlpMANBytP4sZLyZKLZ2N854l9WaecJVpiIKOB6XX7h7J/EbNTIVK2yLKE+jwu5Xgh/4WK1FMKTt XANAdZ6w==; Original-Received: from cpe-45-48-239-195.socal.res.rr.com ([45.48.239.195]:54398 helo=server.local) by gator3053.hostgator.com with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.91) (envelope-from ) id 1hHIaJ-001AsU-Tf; Thu, 18 Apr 2019 20:45:00 -0500 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator3053.hostgator.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lawlist.com X-BWhitelist: no X-Source-IP: 45.48.239.195 X-Source-L: No X-Exim-ID: 1hHIaJ-001AsU-Tf X-Source-Sender: cpe-45-48-239-195.socal.res.rr.com (server.local) [45.48.239.195]:54398 X-Source-Auth: lawlist X-Email-Count: 1 X-Source-Cap: bGF3bGlzdDtsYXdsaXN0O2dhdG9yMzA1My5ob3N0Z2F0b3IuY29t X-Local-Domain: yes X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 192.185.70.14 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:235641 Archived-At: Thank you, Alex, for the suggestions to better organize the new cache design. I did not stop to think that calling memset on every window update potentially carried with it a cost to performance, and the OCD side of my brain wanted to continuously tidy things up. I will just need to keep reminding myself that its okay to leave garbage data where it is so long as I steer clear of it by using a counter. :) I created a minimal working example based upon my interpretation of how to use your sample struct. Was it your intention that each main cache would be defined as follows (and the MWE being nth 0 below): 1. TEMP flavor: w->mc_elts[0] 2. MC flavor: w->mc_elts[1] 3. CH flavor: w->mc_elts[2] 4. FC flavor: w->mc_elts[3] if (BUFFERP (w->contents) && !NILP (BVAR (XBUFFER (w->contents), crosshairs))) { /* Increase the size of the array. */ if (w->mc_elts_allocated == 0) { ++w->mc_nelts; int old_alloc = w->mc_elts_allocated; int new_elts = w->mc_nelts - w->mc_elts_allocated; w->mc_elts = xpalloc (w->mc_elts, &w->mc_elts_allocated, new_elts, INT_MAX, sizeof *w->mc_elts); memset (w->mc_elts + old_alloc, 0, (w->mc_elts_allocated - old_alloc) * sizeof *w->mc_elts); } int max_elts = 25000; w->mc_elts->used += (w->mc_elts->used < max_elts) ? 100 : 0; /* Increase the size of the array. */ if (w->mc_elts->allocated < w->mc_elts->used && w->mc_elts->used < max_elts) { int old_alloc = w->mc_elts->allocated; int new_elts = w->mc_elts->used - w->mc_elts->allocated; w->mc_elts->caches = xpalloc (w->mc_elts->caches, &w->mc_elts->allocated, new_elts, INT_MAX, sizeof *w->mc_elts->caches); memset (w->mc_elts->caches + old_alloc, 0, (w->mc_elts->allocated - old_alloc) * sizeof *w->mc_elts->caches); for (int elt = 0; elt < w->mc_elts->used; ++elt) { w->mc_elts[0].caches[elt].x = elt; double red = elt; w->mc_elts[0].caches[elt].foreground.red = red; w->mc_elts[0].caches[elt].enabled_p = true; } } fprintf (stderr, "w->mc_elts->used (%d) | w->mc_elts->allocated (%d) | w->mc_elts[0].caches[99].x (%d)\n", w->mc_elts->used, w->mc_elts->allocated, w->mc_elts[0].caches[99].x); } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > Date: [04-18-2019 14:02:15] <18 Apr 2019 15:02:15 -0600> > From: Alex Gramiak > To: Keith David Bershatsky > Cc: Emacs Devel > Subject: Re: Universal functions to manage multiple window caches. > > Keith David Bershatsky writes: > > > I am working on feature requests 22873 (multiple fake cursors) and 17684 (crosshairs that track the cursor position). > > > > window.h defines four different caches of fake cursors, with the only difference between them being their names: > > > > struct multiple_cursors_cache *temp_elts; > > ptrdiff_t temp_elts_allocated; > > int temp_nelts; > > > > struct multiple_cursors_cache *mc_elts; > > ptrdiff_t mc_elts_allocated; > > int mc_nelts; > > > > struct multiple_cursors_cache *ch_elts; > > ptrdiff_t ch_elts_allocated; > > int ch_nelts; > > > > struct multiple_cursors_cache *fc_elts; > > ptrdiff_t fc_elts_allocated; > > int fc_nelts; > > Each of the four could just be structs themselves. Something like: > > struct multiple_cursor_cache > { > ptrdiff_t allocated; > ptrdiff_t used; > struct items > { > int x; > int fx; > int y; > int fy; > int hpos; > int vpos; > int wd; > int h; > int cursor_type; > int cursor_width; > struct RGB > { > double red; > double green; > double blue; > } foreground, background; > bool active_p; > int glyph_flavor; > bool enabled_p; > } *caches; > }; > > If you need to differentiate them in a helper procedure, you can add an > enum element to the outermost struct. > > P.S. Why do you need to memset the used portion of the caches on every > window update? I would think that just setting the used/*_nelts count > would be sufficient as long as you make sure not to go past that and > access garbage data.