kou commented on code in PR #13224: URL: https://github.com/apache/arrow/pull/13224#discussion_r882213044
########## c_glib/arrow-glib/memory-pool.cpp: ########## @@ -0,0 +1,194 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <arrow-glib/memory-pool.hpp> + +G_BEGIN_DECLS + +/** + * SECTION: memory-pool + * @section_id: memory-pool-classes + * @title: memory-pool classes + * @include: arrow-glib/arrow-glib.h + * + * #GArrowMemoryPool is a class for memory allocation. + */ + +typedef struct GArrowMemoryPoolPrivate_ { + arrow::MemoryPool* memory_pool; +} GArrowMemoryPoolPrivate; + +enum { + PROP_MEMORY_POOL = 1, +}; + +G_DEFINE_TYPE_WITH_PRIVATE(GArrowMemoryPool, garrow_memory_pool, G_TYPE_OBJECT) + +#define GARROW_MEMORY_POOL_GET_PRIVATE(obj) \ + static_cast<GArrowMemoryPoolPrivate *>( \ + garrow_memory_pool_get_instance_private( \ + GARROW_MEMORY_POOL(obj))) + +static void +garrow_memory_pool_set_property(GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + auto priv = GARROW_MEMORY_POOL_GET_PRIVATE(object); + + switch (prop_id) { + case PROP_MEMORY_POOL: + priv->memory_pool = + static_cast<arrow::MemoryPool *>(g_value_get_pointer(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void +garrow_memory_pool_get_property(GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void +garrow_memory_pool_init(GArrowMemoryPool *object) +{ + auto priv = GARROW_MEMORY_POOL_GET_PRIVATE(object); + new(&priv->memory_pool) arrow::MemoryPool*; +} + +static void +garrow_memory_pool_class_init(GArrowMemoryPoolClass *klass) +{ + GParamSpec *spec; + + auto gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->set_property = garrow_memory_pool_set_property; + gobject_class->get_property = garrow_memory_pool_get_property; + + spec = g_param_spec_pointer("memory-pool", + "Memory Pool", + "The raw arrow::MemoryPool* *", + static_cast<GParamFlags>(G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY)); + g_object_class_install_property(gobject_class, PROP_MEMORY_POOL, spec); +} + +/** + * garrow_default_memory_pool: + * + * Returns: (transfer none): The process-wide default memory pool. + * + * Since: 9.0.0 + */ +GArrowMemoryPool * +garrow_default_memory_pool() +{ + auto memory_pool = arrow::default_memory_pool(); + return garrow_memory_pool_new_raw(memory_pool); +} + +/** + * garrow_memory_pool_get_bytes_allocated: + * @memory_pool: A #GArrowMemoryPool. + * + * Returns: The number of bytes that were allocated and not yet free’d + * through this allocator. + * + * Since: 9.0.0 + */ +gint64 +garrow_memory_pool_get_bytes_allocated(GArrowMemoryPool *memory_pool) +{ + auto arrow_memory_pool = garrow_memory_pool_get_raw(memory_pool); + return arrow_memory_pool->bytes_allocated(); +} + +/** + * garrow_memory_pool_get_max_memory: + * @memory_pool: A #GArrowMemoryPool. + * + * Return peak memory allocation in this memory pool. + * + * Returns: Maximum bytes allocated. If not known (or not implemented), + * returns -1 + * + * Since: 9.0.0 + */ +gint64 +garrow_memory_pool_get_max_memory(GArrowMemoryPool *memory_pool) +{ + auto arrow_memory_pool = garrow_memory_pool_get_raw(memory_pool); + return arrow_memory_pool->max_memory(); +} + +/** + * garrow_memory_pool_get_backend_name: + * @memory_pool: A #GArrowMemoryPool. + * + * The name of the backend used by this MemoryPool (e.g. “system” or + * “jemalloc”). + * Review Comment: ```suggestion * * It should be freed with g_free() when no longer needed. ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
