Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vvzvb-00EcYy-2C for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Feb 2026 15:38:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vvzva-004U3n-2A for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Feb 2026 15:38:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vvzsU-004Q0j-1v for pgsql-hackers@lists.postgresql.org; Fri, 27 Feb 2026 15:35:42 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vvzsR-00000001WG1-2xbs for pgsql-hackers@lists.postgresql.org; Fri, 27 Feb 2026 15:35:41 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 61RFZdOJ854786; Fri, 27 Feb 2026 10:35:39 -0500 From: Tom Lane To: Thomas Munro cc: PostgreSQL Hackers Subject: Re: A stack allocation API In-reply-to: References: Comments: In-reply-to Thomas Munro message dated "Sat, 28 Feb 2026 00:59:42 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <854784.1772206539.1@sss.pgh.pa.us> Date: Fri, 27 Feb 2026 10:35:39 -0500 Message-ID: <854785.1772206539@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Thomas Munro writes: > In the locale code we often use a 1KB array for copies of strings > where we need a NUL-terminated or transcoded version to give a library > function, with a fallback to palloc() + pfree() if we need more space > than that, but: Yeah, I think there are some other use-cases too. > I also wondered if we might have a reasonable case for using alloca(), > where available. It's pretty much the thing we are emulating, but > keeps the stack nice and compact without big holes to step over for > the following call to strcoll_l() or whatever it might be. +1 for investigating alloca(). The one disadvantage I can see to making this coding pattern more common is that it'll result in increased stack usage, which is not great now and will become considerably less great in our hypothetical multithreaded future. If we can fix it so the typical stack consumption is a good deal less than 1KB, that worry would be alleviated. regards, tom lane