KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q64786: _pg_chartpie() Fails to Free Memory in QC 2.00 and QC 2.50

Article: Q64786
Product(s): See article
Version(s): 2.00 2.50
Operating System(s): MS-DOS
Keyword(s): ENDUSER | buglist2.50 | mspl13_c
Last Modified: 17-DEC-1990

The presentation graphics function _pg_chartpie() fails to return
memory allocated from DOS.

Successive calls to _pg_chartpie() will cause three paragraphs of
memory to be allocated from DOS for each call. Because there is no
companion to _pg_initchart() [for example, _pg_closechart()], the
memory allocated by _pg_chartpie() is not returned to DOS until the
program finishes execution.

The program below demonstrates this problem.

Sample Code
-----------

#include <stdlib.h>
#include <graph.h>
#include <pgchart.h>
#include <stdio.h>

#define COUNTRIES 5
float _far value[COUNTRIES] = { 42.5F,  14.3F, 35.2F,  21.3F,
                                32.6F   };
char  _far *category[COUNTRIES] = { "USSR", "GDR", "USA",  "UK",
                                    "Other" };
short _far explode[COUNTRIES] =   { 0,      1,     0,      1,     0 };

void main()
{
    char stringbuff[80];
    chartenv env;
    unsigned sized=0;
    unsigned seg=0;
    /* Get Dos Memory Available on far heap-wait for key hit */
    _settextposition(4,4);
    _dos_allocmem(0xffff,&seg);
    sprintf(stringbuff,"Memory : %u\n",seg);
    _outtext(stringbuff);

    getch();
    if( !_setvideomode( _VRES16COLOR ) )
        exit( 1 );

    _pg_initchart(); /* Initialize chart system    */

    while(1)
        {

    /* Pie chart */

        _pg_defaultchart( &env, _PG_PIECHART, _PG_PERCENT );
        strcpy( env.maintitle.title, "Widget Production" );
        _pg_chartpie( &env, category, value, explode, COUNTRIES );

    /* Display available memory- wait for key hit */

        _settextposition(4,4);
        _dos_allocmem(0xffff,&seg);
        sprintf(stringbuff,"Memory : %u\n",seg);
        _outtext(stringbuff);
        getch();

    }
    _setvideomode( _DEFAULTMODE );
}

Microsoft has confirmed this to be a problem in QuickC version 2.50.
We are researching this problem and will post new information here as
it becomes available.

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.