From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 4C2843856960 for ; Thu, 27 Apr 2023 10:32:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4C2843856960 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682591535; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RYikHyEbniKqrd2k4RVMDZAx0S/pk52s29fvyenXL+Y=; b=SHQ8NWj+qcXBS42Jyx/x0So4NfBWOrpwxgYzIRt5Lk1BGMUjzIlQnVTySjeL+cIK/GchnF QdaKCoqHeGBh102viQxwQ3nJ+pHbCe3iS30Ytejr/V1OYz7JlqPYXowcKB4hZNQ9ydvSaz 1RRDJTr5w24Up0ICL2ER27NlNuuKJ3U= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-207-jnLRNQhUOoWJvU_vZAPpqA-1; Thu, 27 Apr 2023 06:32:12 -0400 X-MC-Unique: jnLRNQhUOoWJvU_vZAPpqA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 05000A0F380; Thu, 27 Apr 2023 10:32:12 +0000 (UTC) Received: from localhost (unknown [10.42.28.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 725771121315; Thu, 27 Apr 2023 10:32:11 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Improve doxygen docs for Date: Thu, 27 Apr 2023 11:32:10 +0100 Message-Id: <20230427103210.1725860-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested powerpc64le-linux. Docs tested on Fedora 37 with Doxygen 1.9.7 from current git master. Pushed to trunk. I'll probably backport this too. -- >8 -- libstdc++-v3/ChangeLog: * include/bits/memory_resource.h: Improve doxygen comments. * include/std/memory_resource: Likewise. --- libstdc++-v3/include/bits/memory_resource.h | 12 ++++ libstdc++-v3/include/std/memory_resource | 63 +++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/libstdc++-v3/include/bits/memory_resource.h b/libstdc++-v3/include/bits/memory_resource.h index 1b9e51ddbbd..f12555d4215 100644 --- a/libstdc++-v3/include/bits/memory_resource.h +++ b/libstdc++-v3/include/bits/memory_resource.h @@ -53,6 +53,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION namespace pmr { /// Class memory_resource + /** + * @ingroup pmr + * @headerfile memory_resource + * @since C++17 + */ class memory_resource { static constexpr size_t _S_max_align = alignof(max_align_t); @@ -104,6 +109,13 @@ namespace pmr #endif // C++17 23.12.3 Class template polymorphic_allocator + + /// Class template polymorphic_allocator + /** + * @ingroup pmr + * @headerfile memory_resource + * @since C++17 + */ template class polymorphic_allocator { diff --git a/libstdc++-v3/include/std/memory_resource b/libstdc++-v3/include/std/memory_resource index 00859262470..fdfc23c95ed 100644 --- a/libstdc++-v3/include/std/memory_resource +++ b/libstdc++-v3/include/std/memory_resource @@ -24,6 +24,9 @@ /** @file include/memory_resource * This is a Standard C++ Library header. + * + * This header declares the @ref pmr (std::pmr) memory resources. + * @ingroup pmr */ #ifndef _GLIBCXX_MEMORY_RESOURCE @@ -35,6 +38,25 @@ #if __cplusplus >= 201703L +/** + * @defgroup pmr Polymorphic memory resources + * + * @anchor pmr + * @ingroup memory + * @since C++17 + * + * Memory resources are classes that implement the `std::pmr::memory_resource` + * interface for allocating and deallocating memory. Unlike traditional C++ + * allocators, memory resources are not value types and are used via pointers + * to the abstract base class. They are only responsible for allocating and + * deallocating, not for construction and destruction of objects. As a result, + * memory resources just allocate raw memory as type `void*` and are not + * templates that allocate/deallocate and construct/destroy a specific type. + * + * The class template `std::pmr::polymorphic_allocator` is an allocator that + * uses a memory resource for its allocations. + */ + #include #include // vector #include // shared_mutex @@ -63,6 +85,11 @@ namespace pmr // Global memory resources /// A pmr::memory_resource that uses `new` to allocate memory + /** + * @ingroup pmr + * @headerfile memory_resource + * @since C++17 + */ [[nodiscard, __gnu__::__returns_nonnull__, __gnu__::__const__]] memory_resource* new_delete_resource() noexcept; @@ -91,6 +118,11 @@ namespace pmr class monotonic_buffer_resource; /// Parameters for tuning a pool resource's behaviour. + /** + * @ingroup pmr + * @headerfile memory_resource + * @since C++17 + */ struct pool_options { /** @brief Upper limit on number of blocks in a chunk. @@ -152,6 +184,11 @@ namespace pmr #ifdef _GLIBCXX_HAS_GTHREADS /// A thread-safe memory resource that manages pools of fixed-size blocks. + /** + * @ingroup pmr + * @headerfile memory_resource + * @since C++17 + */ class synchronized_pool_resource : public memory_resource { public: @@ -218,6 +255,11 @@ namespace pmr #endif /// A non-thread-safe memory resource that manages pools of fixed-size blocks. + /** + * @ingroup pmr + * @headerfile memory_resource + * @since C++17 + */ class unsynchronized_pool_resource : public memory_resource { public: @@ -275,6 +317,27 @@ namespace pmr _Pool* _M_pools = nullptr; }; + /// A memory resource that allocates from a fixed-size buffer. + /** + * The main feature of a `pmr::monotonic_buffer_resource` is that its + * `do_deallocate` does nothing. This makes it very fast because there is no + * need to manage a free list, and every allocation simply returns a new + * block of memory, rather than searching for a suitably-sized free block. + * Because deallocating is a no-op, the amount of memory used by the resource + * only grows until `release()` (or the destructor) is called to return all + * memory to upstream. + * + * A `monotonic_buffer_resource` can be initialized with a buffer that + * will be used to satisfy all allocation requests, until the buffer is full. + * After that a new buffer will be allocated from the upstream resource. + * By using a stack buffer and `pmr::null_memory_resource()` as the upstream + * you can get a memory resource that only uses the stack and never + * dynamically allocates. + * + * @ingroup pmr + * @headerfile memory_resource + * @since C++17 + */ class monotonic_buffer_resource : public memory_resource { public: -- 2.40.0