Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2024-06

Custom NewInstance allocator

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Hairy Pixels

In the manual it at https://www.freepascal.org/docs-html/ref/refse38.html it says "Calling the constructor will provoke a call to the virtual class method NewInstance, which, in its default implementation, calls GetMem, to allocate enough space to hold the class instance data, and then zeroes out the memory."

I'm trying this like below but it crashes. Is this correct? The fact NewInstance returns TObject instead of Pointer doesn't make sense to me and suggests this isn't correct.

  class function TDataObject.NewInstance: TObject;
  begin
    result := TObject(GetMem(InstanceSize));
  end;

Regards,
Ryan Joseph

Reply by email

Olivier Sannier
to Hairy Pixels

Could it be because you do not zero out the allocated memory?

Le 04/06/2024 à 10꞉54, Hairy Pixels via fpc-pascal a écrit :

Show quoted text 15 lines
In the manual it athttps://www.freepascal.org/docs-html/ref/refse38.html it says "Calling the constructor will provoke a call to the virtual class method NewInstance, which, in its default implementation, calls GetMem, to allocate enough space to hold the class instance data, and then zeroes out the memory." I'm trying this like below but it crashes. Is this correct? The fact NewInstance returns TObject instead of Pointer doesn't make sense to me and suggests this isn't correct. class function TDataObject.NewInstance: TObject; begin result := TObject(GetMem(InstanceSize)); end; Regards, Ryan Joseph _______________________________________________ fpc-pascal maillist https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Sven Barth
to Hairy Pixels: In the manual it at https://www.freepascal.org/docs-html/ref/refse38.html it says…

Hairy Pixels via fpc-pascal schrieb am
Di., 4. Juni 2024, 10:54:

Show quoted text 15 lines
In the manual it at https://www.freepascal.org/docs-html/ref/refse38.html it says "Calling the constructor will provoke a call to the virtual class method NewInstance, which, in its default implementation, calls GetMem, to allocate enough space to hold the class instance data, and then zeroes out the memory." I'm trying this like below but it crashes. Is this correct? The fact NewInstance returns TObject instead of Pointer doesn't make sense to me and suggests this isn't correct. class function TDataObject.NewInstance: TObject; begin result := TObject(GetMem(InstanceSize)); end;

You also need to call TObject.InitInstance() on the allocated memory (that should probably be mentioned in the documentation...).

Regards,
Sven

Reply by email

Hairy Pixels
to Sven Barth

Thanks it's working now. The docs at https://www.freepascal.org/docs-html/rtl/system/tobject.newinstance.html confused me also. It says:

" If the memory was allocated, the class will be initialized by a call to InitInstance"

The text "will be" is what confused me. This implies to me it will be done by Object somewhere higher up in the chain. It should read:

"If memory was allocated it must be initialized by a call to InitInstance"

Show quoted text 19 lines
On Jun 4, 2024, at 7:06 PM, Sven Barth via fpc-pascal wrote: Hairy Pixels via fpc-pascal schrieb am Di., 4. Juni 2024, 10:54: In the manual it at https://www.freepascal.org/docs-html/ref/refse38.html it says "Calling the constructor will provoke a call to the virtual class method NewInstance, which, in its default implementation, calls GetMem, to allocate enough space to hold the class instance data, and then zeroes out the memory." I'm trying this like below but it crashes. Is this correct? The fact NewInstance returns TObject instead of Pointer doesn't make sense to me and suggests this isn't correct. class function TDataObject.NewInstance: TObject; begin result := TObject(GetMem(InstanceSize)); end; You also need to call TObject.InitInstance() on the allocated memory (that should probably be mentioned in the documentation...). Regards, Sven _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Regards,
Ryan Joseph

Reply by email

Tony Whyman
to Hairy Pixels: In the manual it at https://www.freepascal.org/docs-html/ref/refse38.html it says…

You may find that compiling with "{$OBJECTCHECKS OFF}" allows your program to run and as long as your object has  no virtual methods nor  does it require its fields to be initialised to zero, then it might even give a useful result - otherwise, you also need to call InitInstance.

Hairy Pixels wrote 192 lines
In the manual it at https://www.freepascal.org/docs-html/ref/refse38.html it says "Calling the constructor will provoke a call to the virtual class method NewInstance, which, in its default implementation, calls GetMem, to allocate enough space to hold the class instance data, and then zeroes out the memory." I'm trying this like below but it crashes. Is this correct? The fact NewInstance returns TObject instead of Pointer doesn't make sense to me and suggests this isn't correct. class function TDataObject.NewInstance: TObject; begin result := TObject(GetMem(InstanceSize)); end; Regards, Ryan Joseph _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal Return-Path: Received: from mail3.mwassocs.co.uk (mail3.mwassocs.co.uk [IPv6:2a00:da00:1800:8207:0:0:0:1]) by olympus.mwassocs.co.uk (8.17.1.9/8.17.1.9/Debian-2) with ESMTP id 454925ln001681 for ; Tue, 4 Jun 2024 10:02:13 +0100 Authentication-Results: mail3.mwassocs.co.uk; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=googlegroups.com header.a=rsa-sha256 header.s=20230601 header.b=QYUmS2JD; dkim-atps=neutral Received: from mwa2023.mwassocs.co.uk (localhost [127.0.0.1]) by mail3.mwassocs.co.uk (8.17.1.9/8.17.1.9/Debian-2) with ESMTPS id 4547BXql783561 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO) for ; Tue, 4 Jun 2024 07:11:33 GMT Received: (from ) by mwa2023.mwassocs.co.uk (8.17.1.9/8.17.1.9/Submit) id 4547BXAJ783560 for ; Tue, 4 Jun 2024 07:11:33 GMT Received: from mail-wr1-x438.google.com (mail-wr1-x438.google.com [IPv6:2a00:1450:4864:20:0:0:0:438]) by mail3.mwassocs.co.uk (8.17.1.9/8.17.1.9/Debian-2) with ESMTPS id 4547BUZr783552 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=FAIL) for ; Tue, 4 Jun 2024 07:11:31 GMT Received: by mail-wr1-x438.google.com with SMTP id ffacd0b85a97d-35e7d4f4243sf466477f8f.1 for ; Tue, 04 Jun 2024 00:11:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717485084; cv=pass; d=google.com; s=arc-20160816; b=z3rh7siQ5LSx2gqOn6Mj2et1j7nRVra3IEAIQP3K+wiLPpUXI7Tr01d/nylJ1HaFGg TKMLH/7nimkBSESeSME1HlbXG/UZ3e0eDyQJiX/+9xPvWikDEfUquqMOn/mNiqw7e0Xd +pZECf4Ja5GvrNIdwhvWwE19XAy47TOFoHfh8g+88q2NBW4fHsKwqVJKpqfi9Ph4V+hq u28lFheObpB69LUI3OFdETpRigKxoVZmMBYY1yGyfHTzR2shJuyPqpj/rx6Ltbp2QHKu YPBSqS9MC+jWyvogY3jalcSBCQOmlTMB2lS5dkJCSFv/U9c+waOqTUnyq9NKuUe13Nqz IrTA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:content-transfer-encoding :in-reply-to:organization:from:content-language:references:to :subject:user-agent:mime-version:date:dkim-filter:message-id :dkim-signature; bh=VKy8eSS7uMgsfe7Vrkk4zMlxj8C0nXu9E/pOm4K0rMk=; fh=GfuQ6oQp7YQ6NU+kiZIdgjvraiHPaEC7d1yzxmt/vc4=; b=0lhn/6GQITvaXqpbaKK84AIaB2cjpSaDetDLj6vUj73e+DeHzE4+kqx30HeD4RUwhZ J8nfrgcc/XKIDNflRql2my0pBwCNIatSqJOWvZNkvdt1UM62LwnaAb4o0nG8e7zb7E6r VGEPv5RotVFDMnrtRhED3pKlLKQkyqBGG6yb0IqUtkyCB/BcBAjhO6sYbO3QGcRs2wPW ZAEb/oSv5DTEO3TYDSHjAwyQ4E/q9WjDtd954my1tHUvaXPbzDnR8YvaTXQ6a1wktIDI ZqGD68N9Fmcf7KsICOqThJrRERmgdzP6247CcqS0PN5CUDoaGMo604eJbDbSpIU6Rymo 0Nrg==; darn=mccallumwhyman.com ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.s=protagio header.b=xOXklYHI; spf=pass (google.com: domain of designates 2a00:51c0::5fd7:bd14 as permitted sender) ; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=lawinegevaar.nl DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1717485084; x=1718089884; darn=mccallumwhyman.com; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender :content-transfer-encoding:in-reply-to:organization:from :content-language:references:to:subject:user-agent:mime-version:date :dkim-filter:message-id:from:to:cc:subject:date:message-id:reply-to; bh=VKy8eSS7uMgsfe7Vrkk4zMlxj8C0nXu9E/pOm4K0rMk=; b=QYUmS2JD9igEh2GCuLqex1YPMWgL7uB576WNGf6qDn+fZKlOid4d7qs1PgHY+W68Vk +AF5wYCuH+KjgYsy8e8K2DBOkBbL7QMUmUq2iXO4uTsSTbN2qmebjobxzZUB/awbrNkc DpSv4Z24x493UjN5hhGLCyrM+pRxniveBouMNV3Qc7+QoGD49+CndPN57Plx4u1nTLuJ UAXkXR++eZpsJHpogQmUJk5WLG8KMyaWQUZnkFNEu+Jxyh+C01AtJDmRV0NmLfv0YS2L achfM5H9S9269rggngPHnt/8+r+oS83GsUlsaKNw5pUqEPW2zT0YEC56r84HP3++p1jU +OQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717485084; x=1718089884; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender :content-transfer-encoding:in-reply-to:organization:from :content-language:references:to:subject:user-agent:mime-version:date :dkim-filter:message-id:x-beenthere:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VKy8eSS7uMgsfe7Vrkk4zMlxj8C0nXu9E/pOm4K0rMk=; b=s+pDimf/3IV8IsmC5TsqIeLKlKJwS5TFxhui3FTG63TZ+tDydvw4bnNjhH0iT1WTwn d71Oh9cANHXmnyIJqzSMo1nO/rj0vWq6uIWLa1ZMjBQEkWWp58AhFnekjeAA+dL+uIan zwxCpqeiVQxSLJvuk4MiTbvHuu9IsOgTLjE/j6m+RZ6CltGh6M/gJq0QTHhIhOoMPScQ LwruJb8SIuiwqie5Z4VHRiqzGGl9ZiJgbs/6Gdyf/qmCgn3tqvFVA10HzADsN1QJgBTS 8WS8DLepmSf5KPE/WxzfxfjQ6bEGYw7tm5hEpcW6ESMo+c5ZSwfj9J17z/zqrKvKeIAw O54Q== X-Forwarded-Encrypted: i=2; AJvYcCUbJ7zImHgTvOY/CvPkA3YTLROjZMH9+/fOSNvvgakuyDOpooN3WhxGjzd6s3IafyrHw7YYfQMfJVk19f8Kj3+2/HLHuQuIodxV4ITWyBY= X-Gm-Message-State: AOJu0YwR3LgUc3P7D0D1NwX+r7T6tG+KXRvnq9PQcf3vhL3kvXP6YxHo Mvmc5l/C+UxBEXF/ZBYquuqq3jsGWukqPWcE0wgenpqOmFVZLvB0 X-Google-Smtp-Source: AGHT+IGO+TgM+9nhzRypTegXKfboZ2tjhVfRxSoBnMbPXIY4R22AxERsWxoRp0gAWBBNpvVsMHN0Ow== X-Received: by 2002:a5d:6e5e:0:b0:354:faf4:fa87 with SMTP id ffacd0b85a97d-35e0f2590e5mr6110059f8f.3.1717485084015; Tue, 04 Jun 2024 00:11:24 -0700 (PDT) X-BeenThere: Received: by 2002:a5d:670d:0:b0:359:7b15:59e6 with SMTP id ffacd0b85a97d-35dbf8e1891ls1138330f8f.2.-pod-prod-06-eu; Tue, 04 Jun 2024 00:11:22 -0700 (PDT) X-Received: by 2002:adf:f212:0:b0:354:fb2a:7da8 with SMTP id ffacd0b85a97d-35e0f26e7femr8277131f8f.20.1717485081908; Tue, 04 Jun 2024 00:11:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717485081; cv=none; d=google.com; s=arc-20160816; b=0jYbhWGukb2FBWfp871tAg7gsm05GLIe4kPRaEkGvBluE6sSrAV2Ek6R1EkCaMBtEH nskx99rb50CGmWj+YVGK7+NggqspltZ+F3ltDf7LzVXH2znr90sDVMkzAtb2Wc8TNqlf Q9WkYFP0EdWw1hhIbSKHmYuRBlJALGIEr9iTCshP/YZLGwh226mTGEQX371KPsJmKidW TIhbKpA+I1Gd0et+7HllUdy9cltEo3x+Y6Em/fv3bRVE8dXn0t0nK5dD/ASlZWcOSIFs BUz59zWOflfM5yRzX8WzTpm66a6AErTZHM93+wy3iBnlRLVmyaYYtrxwJtRJllZp2OCd QDAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:from :content-language:references:to:subject:user-agent:mime-version:date :dkim-signature:dkim-filter:message-id; bh=xsj+P5Hbtlxg9a+C5ARS1vHMPhhnGqY7nUQqi4OzgX0=; fh=KEmKjYo6I4tnlNlyyVLpK9R/qyiCMzQnYmv7XX42lns=; b=tgshVQqqXSaArO2pcE+WDCMQXCd+x5eFYijoiVZPveikv6LUhMf4TgNlGFsEzlkutj xgWVS9/N0luJPU3+WGK2yOuEJDlhm31BFYthFXU/Ww+/2euWRq73HG3R3FhZfTk7KBjV 6FZeg4bnKvTOJnAMfdbM/K7Si7iF3hr+AeT+lEDz4luZIv6uvab/xBv+Ttt14VLN6Y20 XSE73/xLdPEjHPkIZ7+8a7ZFgl9CC5vVC+dyDV3hXrK8eQpvm5kr4Z79svhF78M9t1/u xbidWpj6ecYmDc0pUyuf67jdGrq2E2SM+z3UpT/Hgz/lCzwa/I8Ad/Vawf5aSROmx2rQ NtRQ==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.s=protagio header.b=xOXklYHI; spf=pass (google.com: domain of designates 2a00:51c0::5fd7:bd14 as permitted sender) ; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=lawinegevaar.nl Received: from smtp2.protagio.nl (smtp2.protagio.nl. [2a00:51c0::5fd7:bd14]) by gmr-mx.google.com with ESMTPS id ffacd0b85a97d-35dd0646e78si215661f8f.7.2024.06.04.00.11.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 00:11:21 -0700 (PDT) Received-SPF: pass (google.com: domain of designates 2a00:51c0::5fd7:bd14 as permitted sender) client-ip=2a00:51c0::5fd7:bd14; Message-ID: DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.protagio.nl 8D10127A Date: Tue, 4 Jun 2024 09:11:20 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [firebird-devel] Schemas in Firebird - SYSTEM schema, migration from old versions and plugin objects To: References: Content-Language: en-US From: "'Mark Rotteveel' via firebird-devel" Organization: Me, myself and I In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed X-Original-Sender: X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.s=protagio header.b=xOXklYHI; spf=pass (google.com: domain of designates 2a00:51c0::5fd7:bd14 as permitted sender) ; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=lawinegevaar.nl X-Original-From: Mark Rotteveel Reply-To: Precedence: list Mailing-list: list ; contact List-ID: <firebird-devel.googlegroups.com> X-Spam-Checked-In-Group: X-Google-Group-Id: 664696289522 List-Post: <https://groups.google.com/group/firebird-devel/post>, List-Help: <https://groups.google.com/support/>, List-Archive: <https://groups.google.com/group/firebird-devel List-Subscribe: <https://groups.google.com/group/firebird-devel/subscribe>, List-Unsubscribe: , <https://groups.google.com/group/firebird-devel/subscribe> X-Spam-Status: No, score=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, DMARC_PASS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on mwa2023.mwassocs.co.uk Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail3.mwassocs.co.uk id 4547BUZr783552 On 03/06/2024 16:11, Денис Симонов wrote: > Why not make the default schema PUBLIC, like Postgresql does? > > Let all system tables be located in the SYSTEM schema. There are many > ways to solve backward compatibility problems, for example making all > current RDB$ tables views on the SYSTEM table, or aliases of objects > from the SYSTEM schema. In PostgreSQL, the system tables do not reside in public, but in pg_catalog. Mark

Reply by email