예제 #1
0
static void* heapIncrease(Heap_t uhp, size_t* plen, int* pfl)
  {
  PVOID p = NULL;
  *plen = (size_t)RNDUP(*plen, CB_HEAPBLOCK);
  *pfl = !_BLOCK_CLEAN;
  logwrite("increaseHeap  -                    size : %8u\n", *plen, 0);
  if ( DosSubAllocMem(pbasemem, &p, *plen) )
    return NULL;
  return p;
  }
예제 #2
0
BOOL MemHeapInit(VOID)
  {
  PVOID pheap;
  if ( DosAllocMem(&pbasemem, CB_HEAPTOTAL, PAG_READ | PAG_WRITE) ||
       DosSubSetMem(pbasemem, DOSSUB_INIT | DOSSUB_SPARSE_OBJ, CB_HEAPTOTAL) ||
       DosSubAllocMem(pbasemem, &pheap, CB_HEAPBLOCK - CB_SUBSETOVHD) ||
       (NULL == (hp = _ucreate(pheap, CB_HEAPBLOCK - CB_SUBSETOVHD,
                               !_BLOCK_CLEAN, _HEAP_REGULAR,
                               heapIncrease, heapDecrease))) ||
       _uopen(hp) )
    return FALSE;
#ifdef DEBUGMEM
  openLogFile();
#endif
  return TRUE;
  }
예제 #3
0
파일: os2.c 프로젝트: atupal/mit-scheme
void *
OS2_malloc_noerror (unsigned long size)
{
  PVOID result;
  APIRET rc
    = (DosSubAllocMem (malloc_object,
		       (&result),
		       (size + (sizeof (malloc_header_t)))));
  if (rc == ERROR_DOSSUB_NOMEM)
    return (0);
  if (rc != NO_ERROR)
    {
      char buffer [1024];
      sprintf (buffer, "DosSubAllocMem error: %d.", rc);
      OS2_logic_error (buffer);
    }
  (((malloc_header_t *) result) -> check) = (((char *) result) - 47);
  (((malloc_header_t *) result) -> size) = size;
  return (((malloc_header_t *) result) + 1);
}
예제 #4
0
int main (VOID)

{

  PVOID   pvMemBase       = NULL;       /* Pointer to memory object (pool)*/

  PVOID   apvBlock[NUMBLOCKS] = {NULL}; /* Pointers to memory blocks      */

  ULONG   i               = 0;          /* A loop index                   */

  APIRET  rc              = NO_ERROR;   /* Return code                    */



    /* Allocate the memory pool.  Note the pool is intentionally NOT

       committed here.  OS/2 will commit the memory as needed.           */



  rc = DosAllocMem( &pvMemBase, POOLSIZE, PAG_WRITE );

  if (rc != NO_ERROR) {

    printf("DosAllocMem error:  return code = %u\n", rc);

    return 1;

  }

       /* Make the entire memory object available for Suballocation */



  rc = DosSubSetMem( pvMemBase, DOSSUB_INIT | DOSSUB_SPARSE_OBJ, POOLSIZE );

  if (rc != NO_ERROR) {

    printf("DosSubSetMem error:  return code = %u\n", rc);

    return 1;

  } else { printf("Memory object ready for suballocation.\n"); }



   /* Suballocate the pool into 128 memory blocks, each 80 bytes in size */



  for( i = 0; i < NUMBLOCKS; i++ ) {

    rc = DosSubAllocMem( pvMemBase, &apvBlock[ i ], 80 );

    if( rc != NO_ERROR ) {

      printf( "DosSubAllocMem error: return code = %u  (i = %u)\n", rc, i );

      break;             }

  }



                     /*    USE THE POOL HERE... */



             /* When done, free the 128 memory blocks */



  do {

    rc = DosSubFreeMem(  pvMemBase, apvBlock[ --i ], 80 );

    if (rc != NO_ERROR) {

      printf("DosSubFreeMem error:  return code = %u  (i = %u)\n", rc, i);

      return 1;

    }

  } while( i );

        /* Stop memory block management, and free the memory object */



  rc = DosSubUnsetMem( pvMemBase );

  if (rc != NO_ERROR) {

    printf("DosSubUnsetMem error:  return code = %u\n", rc);

    return 1;

  }



  rc = DosFreeMem( pvMemBase );

  if (rc != NO_ERROR) {

    printf("DosFreeMem error:  return code = %u\n", rc);

    return 1;

  } else {

    printf("Memory freed.\n");

  }



  return NO_ERROR;

}