MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / autoMemoryFreed

Function autoMemoryFreed

src/module.cpp:1088–1116  ·  view source on GitHub ↗

Mark an object as freed in the auto release queue, so that users can still * free things manually if they want. * * The function returns 1 if the object was actually found in the auto memory * pool, otherwise 0 is returned. */

Source from the content-addressed store, hash-verified

1086 * The function returns 1 if the object was actually found in the auto memory
1087 * pool, otherwise 0 is returned. */
1088int autoMemoryFreed(RedisModuleCtx *ctx, int type, void *ptr) {
1089 if (!(ctx->flags & REDISMODULE_CTX_AUTO_MEMORY)) return 0;
1090
1091 int count = (ctx->amqueue_used+1)/2;
1092 for (int j = 0; j < count; j++) {
1093 for (int side = 0; side < 2; side++) {
1094 /* For side = 0 check right side of the array, for
1095 * side = 1 check the left side instead (zig-zag scanning). */
1096 int i = (side == 0) ? (ctx->amqueue_used - 1 - j) : j;
1097 if (ctx->amqueue[i].type == type &&
1098 ctx->amqueue[i].ptr == ptr)
1099 {
1100 ctx->amqueue[i].type = REDISMODULE_AM_FREED;
1101
1102 /* Switch the freed element and the last element, to avoid growing
1103 * the queue unnecessarily if we allocate/free in a loop */
1104 if (i != ctx->amqueue_used-1) {
1105 ctx->amqueue[i] = ctx->amqueue[ctx->amqueue_used-1];
1106 }
1107
1108 /* Reduce the size of the queue because we either moved the top
1109 * element elsewhere or freed it */
1110 ctx->amqueue_used--;
1111 return 1;
1112 }
1113 }
1114 }
1115 return 0;
1116}
1117
1118/* Release all the objects in queue. */
1119void autoMemoryCollect(RedisModuleCtx *ctx) {

Callers 6

RM_FreeStringFunction · 0.85
RM_RetainStringFunction · 0.85
RM_CloseKeyFunction · 0.85
RM_FreeCallReplyFunction · 0.85
RM_FreeDictFunction · 0.85
RM_FreeServerInfoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected