.\" -*- coding: UTF-8 -*- '\" t .\" Copyright 2012, Michael Kerrisk .\" Copyright, the authors of the Linux man-pages project .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH malloc_info 3 "8 فبراير 2026" "صفحات دليل لينكس 6.18" .SH الاسم malloc_info \- تصدير حالة malloc إلى دفق .SH المكتبة مكتبة سي المعيارية (\fIlibc\fP،\ \fI\-lc\fP) .SH موجز .nf \fB#include \fP .P \fBint malloc_info(int \fP\fIoptions\fP\fB, FILE *\fP\fIstream\fP\fB);\fP .fi .SH الوصف تصدّر الدالة \fBmalloc_info\fP() سلسلة XML تصف الحالة الحالية لتنفيذ تخصيص الذاكرة في المستدعي. تُطبع السلسلة على دفق الملف \fIstream\fP. تتضمن السلسلة المُصدّرة معلومات عن جميع الساحات (انظر \fBmalloc\fP(3)). .P كما هو مطبّق حالياً، يجب أن يكون \fIoptions\fP صفراً. .SH "قيمة الإرجاع" عند النجاح، تُعيد \fBmalloc_info\fP() 0. عند الفشل، تُعيد \-1، ويُضبط \fIerrno\fP للإشارة إلى الخطأ. .SH الأخطاء .TP \fBEINVAL\fP \fIoptions\fP كان غير صفري. .SH السمات للاطلاع على شرح للمصطلحات المستخدمة في هذا القسم، انظر \fBattributes\fP(7). .TS allbox; lbx lb lb l l l. الواجهة السمة القيمة T{ .na .nh \fBmalloc_info\fP() T} سلامة الخيوط MT\-Safe .TE .SH المعايير GNU. .SH التاريخ glibc 2.10. .SH ملاحظات تُقدّم معلومات تخصيص الذاكرة كسلسلة XML (بدلاً من بنية C) لأن المعلومات قد تتغير بمرور الوقت (تبعاً للتغييرات في التنفيذ الأساسي). تتضمن سلسلة XML الناتجة حقل إصدار. .P يمكن استخدام الدالة \fBopen_memstream\fP(3) لإرسال مخرجات \fBmalloc_info\fP() مباشرةً إلى مخزن مؤقت في الذاكرة، بدلاً من إرسالها إلى ملف. .P صُمّمت الدالة \fBmalloc_info\fP() لمعالجة أوجه القصور في \fBmalloc_stats\fP(3) و \fBmallinfo\fP(3). .SH أمثلة يقبل البرنامج أدناه ما يصل إلى أربع وسائط لسطر الأوامر، أول ثلاث منها إلزامية. تُحدد الوسيطة الأولى عدد الخيوط التي يجب أن ينشئها البرنامج. تُخصّص جميع الخيوط، بما في ذلك الخيط الرئيس، عدد الكتل الذاكرية المُحدّد بالوسيطة الثانية. تتحكم الوسيطة الثالثة في حجم الكتل التي سيتم تخصيصها. ينشئ الخيط الرئيس كتلًا بهذا الحجم، ويُخصّص الخيط الثاني الذي أنشأه البرنامج كتلًا بحجم مضاعف، ويُخصّص الخيط الثالث كتلًا بحجم ثلاثي، وهكذا. .P يستدعي البرنامج \fBmalloc_info\fP() مرتين لعرض حالة تخصيص الذاكرة. يحدث الاستدعاء الأول قبل إنشاء أي خيوط أو تخصيص ذاكرة. يُنفّذ الاستدعاء الثاني بعد أن تُخصّص جميع الخيوط الذاكرة. .P في المثال التالي، تُحدد وسائط سطر الأوامر إنشاء خيط إضافي واحد، ويُخصّص كل من الخيط الرئيس والخيط الإضافي 10000 كتلة ذاكرة. بعد تخصيص كتل الذاكرة، يُظهر \fBmalloc_info\fP() حالة ساحتي تخصيص. .P .in +4n .EX $ \fBgetconf GNU_LIBC_VERSION\fP glibc 2.13 $ \fB./a.out 1 10000 100\fP ============ Before allocating blocks ============ \& ============ After allocating blocks ============ .EE .in .SS "مصدر البرنامج" .\" SRC BEGIN (malloc_info.c) .EX #include #include #include #include #include #include \& static size_t blockSize; static size_t numThreads; static unsigned int numBlocks; \& static void * thread_func(void *arg) { int tn = (int) arg; \& /* The multiplier \[aq](2 + tn)\[aq] ensures that each thread (including the main thread) allocates a different amount of memory. */ \& for (unsigned int j = 0; j < numBlocks; j++) if (malloc(blockSize * (2 + tn)) == NULL) err(EXIT_FAILURE, "malloc\-thread"); \& sleep(100); /* Sleep until main thread terminates. */ return NULL; } \& int main(int argc, char *argv[]) { int sleepTime; pthread_t *thr; \& if (argc < 4) { fprintf(stderr, "%s num\-threads num\-blocks block\-size [sleep\-time]\[rs]n", argv[0]); exit(EXIT_FAILURE); } \& numThreads = atoi(argv[1]); numBlocks = atoi(argv[2]); blockSize = atoi(argv[3]); sleepTime = (argc > 4) ? atoi(argv[4]) : 0; \& thr = calloc(numThreads, sizeof(*thr)); if (thr == NULL) err(EXIT_FAILURE, "calloc"); \& printf("============ Before allocating blocks ============\[rs]n"); malloc_info(0, stdout); \& /* Create threads that allocate different amounts of memory. */ \& for (size_t tn = 0; tn < numThreads; tn++) { errno = pthread_create(&thr[tn], NULL, thread_func, (void *) tn); if (errno != 0) err(EXIT_FAILURE, "pthread_create"); \& /* If we add a sleep interval after the start\-up of each thread, the threads likely won\[aq]t contend for malloc mutexes, and therefore additional arenas won\[aq]t be allocated (see malloc(3)). */ \& if (sleepTime > 0) sleep(sleepTime); } \& /* The main thread also allocates some memory. */ \& for (unsigned int j = 0; j < numBlocks; j++) if (malloc(blockSize) == NULL) err(EXIT_FAILURE, "malloc"); \& sleep(2); /* Give all threads a chance to complete allocations. */ \& printf("\[rs]n============ After allocating blocks ============\[rs]n"); malloc_info(0, stdout); \& exit(EXIT_SUCCESS); } .EE .\" SRC END .SH "انظر أيضًا" \fBmallinfo\fP(3), \fBmalloc\fP(3), \fBmalloc_stats\fP(3), \fBmallopt\fP(3), \fBopen_memstream\fP(3) .PP .SH ترجمة تُرجمت هذه الصفحة من الدليل بواسطة زايد السعيدي . .PP هذه الترجمة هي وثيقة مجانية؛ راجع .UR https://www.gnu.org/licenses/gpl-3.0.html رخصة جنو العامة الإصدار 3 .UE أو ما بعده للاطلاع على شروط حقوق النشر. لا توجد أي ضمانات. .PP إذا وجدت أي أخطاء في ترجمة صفحة الدليل هذه، يرجى إرسال بريد إلكتروني إلى قائمة بريد المترجمين: .MT kde-l10n-ar@kde.org .ME .