Return-Path: X-Original-To: apmail-qpid-users-archive@www.apache.org Delivered-To: apmail-qpid-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E9FEF10AAE for ; Fri, 28 Mar 2014 14:39:33 +0000 (UTC) Received: (qmail 59575 invoked by uid 500); 28 Mar 2014 14:39:22 -0000 Delivered-To: apmail-qpid-users-archive@qpid.apache.org Received: (qmail 59468 invoked by uid 500); 28 Mar 2014 14:39:19 -0000 Mailing-List: contact users-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@qpid.apache.org Delivered-To: mailing list users@qpid.apache.org Received: (qmail 58982 invoked by uid 99); 28 Mar 2014 14:39:15 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Mar 2014 14:39:14 +0000 X-ASF-Spam-Status: No, hits=-0.1 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of prvs=2164d78395=rhs@alum.mit.edu designates 18.7.68.14 as permitted sender) Received: from [18.7.68.14] (HELO alum-mailsec-scanner-3.mit.edu) (18.7.68.14) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Mar 2014 14:39:08 +0000 X-AuditID: 1207440e-f79c76d000003e2c-16-533589758546 Received: from outgoing-alum.mit.edu (OUTGOING-ALUM.MIT.EDU [18.7.68.33]) by alum-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP id EB.37.15916.57985335; Fri, 28 Mar 2014 10:38:45 -0400 (EDT) Received: from mail-pd0-f178.google.com (mail-pd0-f178.google.com [209.85.192.178]) (authenticated bits=0) (User authenticated as rhs@ALUM.MIT.EDU) by outgoing-alum.mit.edu (8.13.8/8.12.4) with ESMTP id s2SEcivK023911 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Fri, 28 Mar 2014 10:38:45 -0400 Received: by mail-pd0-f178.google.com with SMTP id x10so4937823pdj.37 for ; Fri, 28 Mar 2014 07:38:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=kL2210RKdnDiyqQc2BKJSBEpfYBl/VVACJ7nYSSsWpg=; b=mLFZzglkWhA7f3IHrlndFrp2Q8IhWqucZxs1Ml9aVulKWhNXWwoNblIB86j07zH/ZD PnOA4gjQE7MbNQtHYDDJPh7Jnh2Pyax/gnlyWyeFQ0UKs6MWztQ9j534pW17tdvrCuzE s07RRXNo9ICYHsmH0lbXsbUlVPLqg0mRsKVJ1PDzfbPcHdO+swt8J0FMR9jtit2Wc/br 2ifzfp1f00uNrz68aAsKgsGsJqH9A6IUvKj3AdSN0w/nGmz/znLpXC3j7KSyYuotgSXZ 28fm4reHhZKRgA/Qbxqvbh/mMQL0z5VZHoGdXRU8fmkknKxDiNNzFOuRfHEgstK6klM3 ey3g== MIME-Version: 1.0 X-Received: by 10.68.170.66 with SMTP id ak2mr9089948pbc.5.1396017524334; Fri, 28 Mar 2014 07:38:44 -0700 (PDT) Received: by 10.70.30.228 with HTTP; Fri, 28 Mar 2014 07:38:44 -0700 (PDT) In-Reply-To: <533530B9.5010002@blueyonder.co.uk> References: <533530B9.5010002@blueyonder.co.uk> Date: Fri, 28 Mar 2014 10:38:44 -0400 Message-ID: Subject: Re: question on Proton memory management From: Rafael Schloming To: "users@qpid.apache.org" Content-Type: multipart/alternative; boundary=047d7b86d55ca369b204f5aba814 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrKKsWRmVeSWpSXmKPExsUixO6iqFvaaRpscKrX1OLsiv+MDoweU+88 YAtgjOK2SUosKQvOTM/Tt0vgzvi4qZGx4KdBxYm519gbGLdodDFyckgImEhc/j6PBcIWk7hw bz1bFyMXh5DAZUaJVdsPQzkPmCTuvr7LCFIlJDCRUeLXrwKQhITAXFaJ9rlzwdp5BQQlTs58 AmRzACUKJe7u5Ieo95LYfL6PDcTmFDCQ6N66lwUiri9x/MoKdhCbRUBV4tv2s8wQYwIkOjd+ BLOFBQwlnqz6wQRiswloSmy7vBFsjoiAsUTr4tesIDYz0PwTD+awTGAUnIXkillIUhC2jsS7 vgfMELa2xKres0ww9rKFr5kXMLKuYpRLzCnN1c1NzMwpTk3WLU5OzMtLLdI11svNLNFLTSnd xAgJcL4djO3rZQ4xCnAwKvHwCrSaBguxJpYVV+YeYpTkYFIS5d3XDhTiS8pPqcxILM6ILyrN SS0+xCjBwawkwmtXB5TjTUmsrEotyodJSXOwKInzqi1R9xMSSE8sSc1OTS1ILYLJynBwKEnw OnYANQoWpaanVqRl5pQgpJk4OEGGc0mJFKfmpaQWJZaWZMSDYj6+GBj1ICkeoL0LQG7iLS5I zAWKQrSeYjTmaLq7upGJ49S6DY1MQix5+XmpUuK8B0FKBUBKM0rz4BbBUtsrRnGgv4V5M0Du 4QGmRbh5r4BWMQGt4qoyAllVkoiQkmpgDHR74L78+qScJteYQ+9cO0ycZ/e8NPwZtcR28fKC XQL/ZpoePF/t1Zz6VLcvd53Fzcbjovfld1Tss5vyT971UvmrRVMnrtEIPxW6gblVllU0oY9B o+r5nIjmHbI/Fe/UCIv6nE2wf2o5y/p8ufXk+NjPD6eanGmYkxGxmMOc7e/M3/Lf+GvvKLEU ZyQaajEXFScCAFu2ydNIAwAA X-Virus-Checked: Checked by ClamAV on apache.org --047d7b86d55ca369b204f5aba814 Content-Type: text/plain; charset=ISO-8859-1 On Fri, Mar 28, 2014 at 4:20 AM, Fraser Adams wrote: > I mentioned the other day about the lack of API documentation for things > like message and codec/data > Yeah, I missed those in my documentation pass a few weeks ago. > > It'd be really useful to have documentation for at least the non-obvious > calls. > > One thing I'm currently struggling with is understanding the > ownership/responsibility for the memory of items that consume or return > pn_bytes_t > > What I *think* is the case is that for say pn_data_get_binary if I were > applying that to say the message body then it refers to memory that is > *owned* by the message, so I could access the bytes pointed to by > bytes.start whilst the message was in scope and I wouldn't need to do any > explicit free of bytes.start, however if I wanted to retain that data I'd > have to copy the data into my own buffer before I did say pn_messenger_get > again into the same message instance. > > I guess in the case of data retrieval I'm asking if I don't generally need > to explicitly free the underlying data from a pn_bytes_t because it's owned > by the underlying message (or pn_data if I'm doing lower level things). > Your assumption is correct. When pn_bytes_t is returned it is giving you a pointer to memory owned by the object you are accessing. > > > So what about the reverse case? If I'm going to do pn_data_put_binary I > clearly need to create a pn_bytes_t and the start pointer for that would > likely be a block of memory that I've malloc'd - so at which point is the > ownership of that data "transferred" so that I can free my client side > buffer? I'm *guessing* that pn_data_put_binary copies the data from the > byte array pointed to by the pn_bytes_t start somewhere into the underlying > pn_data_t but that's only an assumption on my part because that behaviour > seems to make logical sense to me, it's far from clear that this is what is > actually going own. > Your assumption is again correct. > > Clearly understanding ownership of dynamically allocated memory is pretty > important for application efficiency (I'd like to avoid unnecessary copies) > and correctness (I definitely want to avoid leaks) and this sort of thing > gets even more important to understand if one ends up passing or retrieving > more complex data structures such as maps or lists that might contain > binary elements. > The missing docs should be up soon. --Rafael --047d7b86d55ca369b204f5aba814--