From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 25177 invoked from network); 17 Aug 2020 20:17:28 -0000 Received: from minnie.tuhs.org (45.79.103.53) by inbox.vuxu.org with ESMTPUTF8; 17 Aug 2020 20:17:28 -0000 Received: by minnie.tuhs.org (Postfix, from userid 112) id C907D9E176; Tue, 18 Aug 2020 06:17:21 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id 9B8229CAB3; Tue, 18 Aug 2020 06:16:23 +1000 (AEST) Authentication-Results: minnie.tuhs.org; dkim=pass (2048-bit key; unprotected) header.d=majumdar-org-uk.20150623.gappssmtp.com header.i=@majumdar-org-uk.20150623.gappssmtp.com header.b="kA5TjTUZ"; dkim-atps=neutral Received: by minnie.tuhs.org (Postfix, from userid 112) id B40289CAB3; Tue, 18 Aug 2020 06:16:20 +1000 (AEST) Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) by minnie.tuhs.org (Postfix) with ESMTPS id 3D5C99C8BB for ; Tue, 18 Aug 2020 06:16:19 +1000 (AEST) Received: by mail-lj1-f178.google.com with SMTP id t6so18887753ljk.9 for ; Mon, 17 Aug 2020 13:16:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=majumdar-org-uk.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2PT5+VZngCaT4DhtBTG+S4uQu/ujWrOuKV2j9VVo26s=; b=kA5TjTUZKWrkxWtI5jmzhtmqZT/JckGFrIfb2jPqWL20zsWxw5Ng+08G8Cw0/LCEdj rNHKdRIYYRkiatalgTjpEamiG/wceql/kh8D5PvJLGWDIfWNBqhlx70FO46t3J99JBVk iNzNyk1SJOdQ9k+XvVPcdZavsuIPe1djMar4dT5lAAUXEemcUg5lDTI4DiA4Z6PZ++oM OyCuJRyihXCGQKu2P/KDoyENjhyh1MlOL11p1kiWmGPH5DcpUmEKtqXn+YKU1miLwGLW Gmc8Fyfzbk3coeP675F3IxCIbV8WJITQl5ykAyiOs1jabHz/N0byzAnNOP2ZBca09XCf ccvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2PT5+VZngCaT4DhtBTG+S4uQu/ujWrOuKV2j9VVo26s=; b=o0uMaq51wkk05iwY2DnMbQKyI3oTBzpxvJTH/Mw1FJPMk5vor927fSLkIN5pRiFrbr ExbP8F1JBckDb2tt296HPOpzfEeGzKugJpplUpsgaUvyrRX4XmjJdAxhFzHmm2mxTXvi GTGtntXTxmCk9WlSmECCq1e+xHFG/5xONE9Ps2yb2ZM3Xg0jbPkF0MxayUiISSq80Nu3 2MVMq/fvf/oanSEePWMvo78R7PxC/VBf42aYoirS6JkJ5uGLAxQJplZofly9YVF2nNC1 Qqi9yg0EQVyIFDNU+n5Q4GrG1LGPRiNH16tFD9+llbqxhaO/Z1QhmXqRIqd3U1oBDMF1 WUlQ== X-Gm-Message-State: AOAM5314Frkw5elyi5uLnOOif0X/zx98aavW5fbqasS+nC1/1IsurptV 8U+QL7Hk21BR/tw3zNgYwUcr4YmJtEDEtGZIw13sUQ== X-Google-Smtp-Source: ABdhPJzI7IzxPWRJ45D9zH07r6F3M5PUz29lLys2dYbRAd4MScxcn1FH10dVgAlHv98eXUe+6S2oRuRXx/NFfl6XoUg= X-Received: by 2002:a2e:8957:: with SMTP id b23mr7699799ljk.331.1597695377483; Mon, 17 Aug 2020 13:16:17 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Dibyendu Majumdar Date: Mon, 17 Aug 2020 21:16:06 +0100 Message-ID: To: Dan Cross Content-Type: text/plain; charset="UTF-8" Subject: Re: [TUHS] Memory management in Dennis Ritchie's C Compiler X-BeenThere: tuhs@minnie.tuhs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: The Unix Heritage Society mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: The TUHS Errors-To: tuhs-bounces@minnie.tuhs.org Sender: "TUHS" On Mon, 17 Aug 2020 at 17:13, Dan Cross wrote: > From my light skimming of V10 sources, it appears that the various components of the default C compiler (that is, not LCC) either use malloc/free or call `sbrk` directly. > Yes, it only uses sbrk(). One consequence I think is that sbrk() expands the process memory without invalidating existing use of memory - so the code is able to periodically expand heap while retaining all existing allocations. A simple workaround I used was to preallocate a heap and just stub out sbrk() calls - so that works. So in essence given a single chunk of memory (if large enough - which is still quite small by today's standards) the compiler manages fine. However I find this unsatisfactory and would like to improve it. But it is a bit difficult to understand how the memory is being used. Memory can be used for declarations, trees (for expressions) and strings as far as I can tell. Strings actually use the tree allocation, and just pretend that a node is a string. It seems that tree memory is allocated in a stack discipline. But what puzzled me is that when a tree starts, about 512 bytes of memory are left as gap for declarations to use. I have been trying to think in what circumstances would you encounter a declaration while parsing an expression - perhaps cast expressions? Anyway - if a declaration occurs inside an expression (i.e. tree) then it only has 512 bytes available. Of course this could be made bigger ... but at the least I would like to have separate heaps for declarations, trees and strings. I guess no one really dug into this code - as presumably once PCC came along the original compiler by Dennis stopped being used. Thanks and Regards Dibyendu