/** * camel_mempool_alloc: * @pool: a #CamelMemPool * @size: * * Allocate a new data block in the mempool. Size will * be rounded up to the mempool's alignment restrictions * before being used. * * Since: 2.32 **/ gpointer camel_mempool_alloc (CamelMemPool *pool, register gint size) { size = (size + pool->align) & (~(pool->align)); if (size >= pool->threshold) { MemPoolThresholdNode *n; n = g_malloc (ALIGNED_SIZEOF (*n) + size); n->next = pool->threshold_blocks; pool->threshold_blocks = n; return (gchar *) n + ALIGNED_SIZEOF (*n); } else { register MemPoolNode *n; n = pool->blocks; if (n && n->free >= size) { n->free -= size; return (gchar *) n + ALIGNED_SIZEOF (*n) + n->free; } /* maybe we could do some sort of the free blocks based on size, but * it doubt its worth it at all */ n = g_malloc (ALIGNED_SIZEOF (*n) + pool->blocksize); n->next = pool->blocks; pool->blocks = n; n->free = pool->blocksize - size; return (gchar *) n + ALIGNED_SIZEOF (*n) + n->free; } }
/// Create a message. /// \param type The type of message to create. /// \param data Associate this data to the message. /// \param len Then lenght(byte number) of the data. /// \return !=NULL The message which created. /// \return ==NULL Create message failed. GsmTaskMessage *__gsmCreateMessage(GsmTaskMessageType type, const char *dat, int len) { GsmTaskMessage *message = __gsmPortMalloc(ALIGNED_SIZEOF(GsmTaskMessage) + len); // GsmTaskMessage *message = __gsmPortMalloc(2 + len); if (message != NULL) { message->type = type; message->length = len; memcpy(&message[1], dat, len); } return message; }