⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 talloc_guide.txt

📁 samba服务器!
💻 TXT
📖 第 1 页 / 共 2 页
字号:
the talloc_realloc_size() function is useful when the type is not known so the typesafe talloc_realloc() cannot be used.=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-void *talloc_steal(const void *new_ctx, const void *ptr);The talloc_steal() function changes the parent context of a tallocpointer. It is typically used when the context that the pointer iscurrently a child of is going to be freed and you wish to keep thememory for a longer time. The talloc_steal() function returns the pointer that you pass it. Itdoes not have any failure modes.NOTE: It is possible to produce loops in the parent/child relationshipif you are not careful with talloc_steal(). No guarantees are providedas to your sanity or the safety of your data if you do this.talloc_steal (new_ctx, NULL) will return NULL with no sideeffects.=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-size_t talloc_total_size(const void *ptr);The talloc_total_size() function returns the total size in bytes usedby this pointer and all child pointers. Mostly useful for debugging.Passing NULL is allowed, but it will only give a meaningful result iftalloc_enable_leak_report() or talloc_enable_leak_report_full() hasbeen called.=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-size_t talloc_total_blocks(const void *ptr);The talloc_total_blocks() function returns the total memory blockcount used by this pointer and all child pointers. Mostly useful fordebugging.Passing NULL is allowed, but it will only give a meaningful result iftalloc_enable_leak_report() or talloc_enable_leak_report_full() hasbeen called.=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-void talloc_report_depth_cb(const void *ptr, int depth, int max_depth,			    void (*callback)(const void *ptr,			    		     int depth, int max_depth,					     int is_ref,					     void *priv),			    void *priv);This provides a more flexible reports than talloc_report(). Itwill recursively call the callback for the entire tree of memoryreferenced by the pointer. References in the tree are passed withis_ref = 1 and the pointer that is referenced.You can pass NULL for the pointer, in which case a report isprinted for the top level memory context, but only iftalloc_enable_leak_report() or talloc_enable_leak_report_full()has been called.The recursion is stopped when depth >= max_depth.max_depth = -1 means only stop at leaf nodes.=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-void talloc_report_depth_file(const void *ptr, int depth, int max_depth, FILE *f);This provides a more flexible reports than talloc_report(). Itwill let you specify the depth and max_depth.=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-void talloc_report(const void *ptr, FILE *f);The talloc_report() function prints a summary report of all memoryused by ptr. One line of report is printed for each immediate child ofptr, showing the total memory and number of blocks used by that child.You can pass NULL for the pointer, in which case a report is printedfor the top level memory context, but only iftalloc_enable_leak_report() or talloc_enable_leak_report_full() hasbeen called.=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-void talloc_report_full(const void *ptr, FILE *f);This provides a more detailed report than talloc_report(). It willrecursively print the ensire tree of memory referenced by thepointer. References in the tree are shown by giving the name of thepointer that is referenced.You can pass NULL for the pointer, in which case a report is printedfor the top level memory context, but only iftalloc_enable_leak_report() or talloc_enable_leak_report_full() hasbeen called.=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-void talloc_enable_leak_report(void);This enables calling of talloc_report(NULL, stderr) when the programexits. In Samba4 this is enabled by using the --leak-report commandline option.For it to be useful, this function must be called before any othertalloc function as it establishes a "null context" that acts as thetop of the tree. If you don't call this function first then passingNULL to talloc_report() or talloc_report_full() won't give you thefull tree printout.Here is a typical talloc report:talloc report on 'null_context' (total 267 bytes in 15 blocks)        libcli/auth/spnego_parse.c:55  contains     31 bytes in   2 blocks        libcli/auth/spnego_parse.c:55  contains     31 bytes in   2 blocks        iconv(UTF8,CP850)              contains     42 bytes in   2 blocks        libcli/auth/spnego_parse.c:55  contains     31 bytes in   2 blocks        iconv(CP850,UTF8)              contains     42 bytes in   2 blocks        iconv(UTF8,UTF-16LE)           contains     45 bytes in   2 blocks        iconv(UTF-16LE,UTF8)           contains     45 bytes in   2 blocks=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-void talloc_enable_leak_report_full(void);This enables calling of talloc_report_full(NULL, stderr) when theprogram exits. In Samba4 this is enabled by using the--leak-report-full command line option.For it to be useful, this function must be called before any othertalloc function as it establishes a "null context" that acts as thetop of the tree. If you don't call this function first then passingNULL to talloc_report() or talloc_report_full() won't give you thefull tree printout.Here is a typical full report:full talloc report on 'root' (total 18 bytes in 8 blocks)    p1                             contains     18 bytes in   7 blocks (ref 0)        r1                             contains     13 bytes in   2 blocks (ref 0)            reference to: p2        p2                             contains      1 bytes in   1 blocks (ref 1)        x3                             contains      1 bytes in   1 blocks (ref 0)        x2                             contains      1 bytes in   1 blocks (ref 0)        x1                             contains      1 bytes in   1 blocks (ref 0)=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-void talloc_enable_null_tracking(void);This enables tracking of the NULL memory context without enabling leakreporting on exit. Useful for when you want to do your own leakreporting call via talloc_report_null_full();=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-void talloc_disable_null_tracking(void);This disables tracking of the NULL memory context.=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-(type *)talloc_zero(const void *ctx, type);The talloc_zero() macro is equivalent to:  ptr = talloc(ctx, type);  if (ptr) memset(ptr, 0, sizeof(type));=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-void *talloc_zero_size(const void *ctx, size_t size)The talloc_zero_size() function is useful when you don't have a known type=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-void *talloc_memdup(const void *ctx, const void *p, size_t size);The talloc_memdup() function is equivalent to:  ptr = talloc_size(ctx, size);  if (ptr) memcpy(ptr, p, size);=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-char *talloc_strdup(const void *ctx, const char *p);The talloc_strdup() function is equivalent to:  ptr = talloc_size(ctx, strlen(p)+1);  if (ptr) memcpy(ptr, p, strlen(p)+1);This functions sets the name of the new pointer to the passedstring. This is equivalent to:   talloc_set_name_const(ptr, ptr)=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-char *talloc_strndup(const void *t, const char *p, size_t n);The talloc_strndup() function is the talloc equivalent of the Clibrary function strndup()This functions sets the name of the new pointer to the passedstring. This is equivalent to:   talloc_set_name_const(ptr, ptr)=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-char *talloc_vasprintf(const void *t, const char *fmt, va_list ap);The talloc_vasprintf() function is the talloc equivalent of the Clibrary function vasprintf()=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-char *talloc_asprintf(const void *t, const char *fmt, ...);The talloc_asprintf() function is the talloc equivalent of the Clibrary function asprintf()This functions sets the name of the new pointer to the passedstring. This is equivalent to:   talloc_set_name_const(ptr, ptr)=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-char *talloc_asprintf_append(char *s, const char *fmt, ...);The talloc_asprintf_append() function appends the given formatted string to the given string. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-(type *)talloc_array(const void *ctx, type, uint_t count);The talloc_array() macro is equivalent to:  (type *)talloc_size(ctx, sizeof(type) * count);except that it provides integer overflow protection for the multiply,returning NULL if the multiply overflows.=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-void *talloc_array_size(const void *ctx, size_t size, uint_t count);The talloc_array_size() function is useful when the type is notknown. It operates in the same way as talloc_array(), but takes a sizeinstead of a type.=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-(typeof(ptr)) talloc_array_ptrtype(const void *ctx, ptr, uint_t count);The talloc_ptrtype() macro should be used when you have a pointer to an arrayand want to allocate memory of an array to point at with this pointer. When compilingwith gcc >= 3 it is typesafe. Note this is a wrapper of talloc_array_size()and talloc_get_name() will return the current location in the source file.and not the type.=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-void *talloc_realloc_fn(const void *ctx, void *ptr, size_t size);This is a non-macro version of talloc_realloc(), which is useful as libraries sometimes want a ralloc function pointer. A realloc()implementation encapsulates the functionality of malloc(), free() andrealloc() in one call, which is why it is useful to be able to passaround a single function pointer.=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-void *talloc_autofree_context(void);This is a handy utility function that returns a talloc contextwhich will be automatically freed on program exit. This can be usedto reduce the noise in memory leak reports.=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-void *talloc_check_name(const void *ptr, const char *name);This function checks if a pointer has the specified name. If it doesthen the pointer is returned. It it doesn't then NULL is returned.=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-(type *)talloc_get_type(const void *ptr, type);This macro allows you to do type checking on talloc pointers. It isparticularly useful for void* private pointers. It is equivalent tothis:   (type *)talloc_check_name(ptr, #type)=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-talloc_set_type(const void *ptr, type);This macro allows you to force the name of a pointer to be aparticular type. This can be used in conjunction withtalloc_get_type() to do type checking on void* pointers.It is equivalent to this:   talloc_set_name_const(ptr, #type)=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-talloc_get_size(const void *ctx);This function lets you know the amount of memory alloced so far bythis context. It does NOT account for subcontext memory.This can be used to calculate the size of an array.=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-void *talloc_find_parent_byname(const void *ctx, const char *name);Find a parent memory context of the current context that has the givenname. This can be very useful in complex programs where it may bedifficult to pass all information down to the level you need, but youknow the structure you want is a parent of another context.=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-(type *)talloc_find_parent_bytype(ctx, type);Like talloc_find_parent_byname() but takes a type, making it typesafe.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -