本文整理汇总了C++中DosAllocMem函数的典型用法代码示例。如果您正苦于以下问题:C++ DosAllocMem函数的具体用法?C++ DosAllocMem怎么用?C++ DosAllocMem使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DosAllocMem函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MapAlignedPages
static void *
MapAlignedPages(size_t size, size_t alignment)
{
int recursions = -1;
/* make up to OS2_MAX_RECURSIONS attempts to get an aligned block
* of the right size by recursively allocating blocks of unaligned
* free memory until only an aligned allocation is possible
*/
void *p = MapAlignedPagesRecursively(size, alignment, recursions);
if (p)
return p;
/* if memory is heavily fragmented, the recursive strategy may fail;
* instead, use the "expensive" strategy: allocate twice as much
* as requested and return an aligned address within this block
*/
if (DosAllocMem(&p, 2 * size,
OBJ_ANY | PAG_COMMIT | PAG_READ | PAG_WRITE)) {
JS_ALWAYS_TRUE(DosAllocMem(&p, 2 * size,
PAG_COMMIT | PAG_READ | PAG_WRITE) == 0);
}
jsuword addr = reinterpret_cast<jsuword>(p);
addr = (addr + (alignment - 1)) & ~(alignment - 1);
return reinterpret_cast<void *>(addr);
}
示例2: malloc
/*
* This function calls the allocation function depending on which
* method was compiled into the library: it can be native allocation
* (DosAllocMem/DosFreeMem) or C-Library based allocation (malloc/free).
* Actually, for pixel buffers that we use this function for, cairo
* uses _cairo_malloc_abc, so we use that here, too. And use the
* change to check the size argument
*/
void *_buffer_alloc (size_t a, size_t b, const unsigned int size)
{
size_t nbytes;
void *buffer = NULL;
if (!a || !b || !size ||
a >= INT32_MAX / b || a*b >= INT32_MAX / size) {
return NULL;
}
nbytes = a * b * size;
#ifdef OS2_USE_PLATFORM_ALLOC
/* Using OBJ_ANY on a machine that isn't configured for hi-mem
* will cause ERROR_INVALID_PARAMETER. If this occurs, or this
* build doesn't have hi-mem enabled, fall back to using lo-mem.
*/
#ifdef OS2_HIGH_MEMORY
if (!DosAllocMem (&buffer, nbytes,
OBJ_ANY | PAG_READ | PAG_WRITE | PAG_COMMIT))
return buffer;
#endif
if (DosAllocMem (&buffer, nbytes,
PAG_READ | PAG_WRITE | PAG_COMMIT))
return NULL;
#else
/* Clear the malloc'd buffer the way DosAllocMem() does. */
buffer = malloc (nbytes);
if (buffer) {
memset (buffer, 0, nbytes);
}
#endif
return buffer;
}
示例3: hia_wmCreate
MRESULT hia_wmCreate(HWND hwnd,MPARAM mp1,MPARAM mp2)
{
HIA *hia = NULL;
HIABuf *hiabuf = NULL;
HIANotifWnd *notifList = NULL;
ULONG notifListAllocSize = HIA_NOTIFLIST_DEFAULT_SIZE;
HWND hwndOwner = WinQueryWindow(hwnd,QW_OWNER);
USHORT Id = WinQueryWindowUShort(hwnd,QWS_ID);
int i;
if (DosAllocMem((PPVOID)&hiabuf,sizeof(HIABuf),fALLOC))
return MRFROMLONG(TRUE);
#ifdef DEBUG
assert(hiabuf!=NULL);
#endif
HIABufClear(hiabuf);
if (DosAllocMem((PPVOID)¬ifList,sizeof(HIANotifWnd)*notifListAllocSize,fALLOC))
return MRFROMLONG(TRUE);
#ifdef DEBUG
assert(notifList!=NULL);
#endif
for (i=0;i<notifListAllocSize;i++)
{
notifList[i].hwnd = NULLHANDLE;
notifList[i].id = 0;
}
if (DosAllocMem((PPVOID)&hia,sizeof(HIA),fALLOC))
return MRFROMLONG(TRUE);
#ifdef DEBUG
assert(hia!=NULL);
#endif
hia->hwndHIA = hwnd;
hia->inbuf = hiabuf;
hia->kbdtype = HAN_KBD_2;
hia->hanmode = HCH_ENG;
hia->insertmode = HAN_INSERT;
hia->hcode = HCH_JSY;
hia->isHanjaKey = hia_defaultHanjaKey;
hia->isSpecialCharKey = hia_defaultSpecialCharKey;
hia->notifListAllocSize = notifListAllocSize;
hia->notifList = notifList;
hia->notifList[0].hwnd = hwndOwner;
hia->notifList[0].id = Id;
hia->responseTo = &(hia->notifList[0]);
hia->hwndHCHLB = NULLHANDLE;
hia->fRunningHCHLB = FALSE;
hia->scselIndex = 0;
if (!WinSetWindowPtr(hwnd,WINWORD_INSTANCE,(PVOID)hia))
return MRFROMLONG(TRUE);
return 0L;
}
示例4: DosAllocMem
ExecutablePool::Allocation ExecutablePool::systemAlloc(size_t n)
{
void* allocation = NULL;
if (DosAllocMem(&allocation, n, OBJ_ANY|PAG_COMMIT|PAG_READ|PAG_WRITE) &&
DosAllocMem(&allocation, n, PAG_COMMIT|PAG_READ|PAG_WRITE))
CRASH();
ExecutablePool::Allocation alloc = {reinterpret_cast<char*>(allocation), n};
return alloc;
}
示例5: ReadLoopThread
void APIENTRY ReadLoopThread()
{
THREAD *pstThd = pstThread;
CONFIG *pCfg = &pstThd->stCfg;
THREADCTRL *pThread = &pstThd->stThread;
BOOL bReadComplete;
CHAR *pString;
APIRET rc;
BOOL bSkipRead = FALSE;
char szMessage[80];
ULONG ulStringLength;
ULONG ulPostCount;
// DosSetPriority(PRTYS_THREAD,PRTYC_FOREGROUNDSERVER,-28L,0);
DosSetPriority(PRTYS_THREAD,PRTYC_REGULAR,-10L,0);
ulStringLength = pCfg->wReadStringLength;
DosAllocMem((PPVOID)&pString,10010,(PAG_COMMIT | PAG_WRITE | PAG_READ));
while (!pThread->bStopThread)
{
if (ulStringLength != pCfg->wReadStringLength)
{
DosFreeMem(pString);
ulStringLength = pCfg->wReadStringLength;
DosAllocMem((PPVOID)&pString,(ulStringLength + 10),(PAG_COMMIT | PAG_WRITE | PAG_READ));
}
if (pCfg->bHalfDuplex)
{
while ((rc = DosWaitEventSem(hevStartReadSem,10000)) != 0)
if (rc == ERROR_SEM_TIMEOUT)
{
ErrorNotify(pstThd,"Read start semaphore timed out");
bSkipRead = TRUE;
}
else
{
sprintf(szMessage,"Read start semaphore error - rc = %u",rc);
ErrorNotify(pstThd,szMessage);
}
DosResetEventSem(hevStartReadSem,&ulPostCount);
}
if (bSkipRead)
bSkipRead = FALSE;
else
{
if (!pCfg->bReadCharacters)
bReadComplete = ReadString(pstThd,pString);
else
bReadComplete = ReadCharacters(pstThd,pString);
if (bReadComplete)
DosPostEventSem(hevStartWriteSem);
}
}
DosFreeMem(pString);
DosPostEventSem(hevKillReadThreadSem);
DosExit(EXIT_THREAD,0);
}
示例6: getinfo
void getinfo()
{ char buf[1024];
char *pbuf,*pbuf1,*pbuf2;
ULONG rc,ulEnv,ulPTDA,ulSeg,ulErrorClass,ulErrorAction,ulErrorLoc;
PID pid;
USHORT cb,usEnvHob,usEnvHar;
FILE *f;
char buf1[1000];
for (rc=0,pid=0;rc==0 && pid!=0x3a;) {
rc=DosPerfSysCall(0xC5,(ULONG)buf,sizeof(buf),0); //get thread info
pid=(PID)(*((USHORT*)&buf[18]));
}
ulPTDA=*(ULONG*)&buf[12];
printf("%i PID %X PTDA %X\n",rc,pid,ulPTDA);
rc=DosPerfSysCall(0xC1,(ULONG)buf,sizeof(buf),ulPTDA); //get PTDA
usEnvHob=*((USHORT*)&buf[272]);
printf("%i ENVHOB %04X\n",rc,usEnvHob);
rc=DosPerfSysCall(0xD0,(ULONG)buf,0x10,(ULONG)usEnvHob); //get env hob info
usEnvHar=*((USHORT*)&buf[0]);
printf("%i ENVHAR %04X\n",rc,usEnvHar);
rc=DosPerfSysCall(0xCD,(ULONG)buf,0x16,(ULONG)usEnvHar); //get env arena record
ulEnv=(ULONG)(*((USHORT*)&buf[6]))<<16;
printf("%i ENV ADDR %08X\n",rc,ulEnv);
DosAllocMem((void**)&pbuf2,0x1000,0x13);
rc=DosPerfSysCall(0xDB,(ULONG)pbuf2,ulPTDA,0);
printf("0xDB %i\n",rc);
DosAllocMem((void**)&pbuf,0x1000,0x13);
//get linear memory info
rc=DosPerfSysCall(0xDC,(ULONG)pbuf,ulEnv,ulPTDA);
printf("0xDC %i\n",rc);
f=fopen("DC.TXT","w");
fwrite(pbuf,0x1000,1,f);
fclose(f);
DosAllocMem((void**)&pbuf1,0x114,0x13);
memset(pbuf1,0,0x114);
rc=DosPerfSysCall(0xD9,(ULONG)&pbuf1,0,0);
printf("%i %p %p %s\n",rc,pbuf1,&pbuf1,pbuf1);
f=fopen("D9.TXT","w");
fwrite(pbuf1,0x114,1,f);
fclose(f);
DosFreeMem(pbuf);
DosFreeMem(pbuf1);
DosFreeMem(pbuf2);
}
示例7: DosAllocMem
void* OSAllocator::reserveUncommitted(size_t bytes, Usage, bool writable, bool executable)
{
void* result = NULL;
if (DosAllocMem(&result, bytes, OBJ_ANY | protection(writable, executable)) &&
DosAllocMem(&result, bytes, protection(writable, executable)))
{ CRASH();
}
return result;
}
示例8: defined
void* OSAllocator::reserveUncommitted(size_t bytes, Usage, bool writable, bool executable)
{
void* result = NULL;
if (
#if defined(MOZ_OS2_HIGH_MEMORY)
DosAllocMem(&result, bytes, OBJ_ANY | protection(writable, executable)) &&
#endif
DosAllocMem(&result, bytes, protection(writable, executable)))
{ CRASH();
}
return result;
}
示例9: suplibOsPageAlloc
int suplibOsPageAlloc(PSUPLIBDATA pThis, size_t cPages, void **ppvPages)
{
NOREF(pThis);
*ppvPages = NULL;
int rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY);
if (rc == ERROR_INVALID_PARAMETER)
rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY);
if (!rc)
rc = VINF_SUCCESS;
else
rc = RTErrConvertFromOS2(rc);
return rc;
}
示例10: Clipper_PasteTextToVIOWindow
// Frame_window - текстовое окно.
VOID Clipper_PasteTextToVIOWindow( HWND Frame_window )
{
// Если в Clipboard есть какие-то строки:
CHAR Short_string[ 4 ] = ""; GetStringFromClipboard( Enhancer.Application, Short_string, 4 );
if( Short_string[ 0 ] != 0 )
{
// Сбрасываем Clipboard и запоминаем строки еще раз как CF_TEXT.
// Это необходимо делать потому, что если строки были взяты из другого текстового окна,
// то при нажатой клавише Shift другие текстовые окна не могут вставить последние буквы.
// Отводим память для текста.
PCHAR Clipboard_text = NULL; INT Length = 16384;
if( DosAllocMem( (PPVOID) &Clipboard_text, Length, PAG_ALLOCATE ) != NO_ERROR ) return;
// Забираем текст из Clipboard и тут же добавляем его в Clipboard.
GetStringFromClipboard( Enhancer.Application, Clipboard_text, Length ); PutStringIntoClipboard( Enhancer.Application, Clipboard_text );
// Освобождаем память.
DosFreeMem( Clipboard_text ); Clipboard_text = NULL;
// Узнаем окно картинки.
HWND SysMenu_window = WinWindowFromID( Frame_window, FID_SYSMENU );
// Если в меню есть строка для вставки текста - посылаем в окно команду от нее.
if( MenuItemIsPresent( SysMenu_window, SM_VIO_PASTE ) )
WinPostMsg( Frame_window, WM_SYSCOMMAND, (MPARAM) SM_VIO_PASTE, MPFROM2SHORT( CMDSRC_MENU, 0 ) );
}
// Возврат.
return;
}
示例11: usalo_getbuf
static void *
usalo_getbuf(SCSI *usalp, long amt)
{
ULONG rc;
#ifdef DEBUG
fprintf((FILE *)usalp->errfile, "usalo_getbuf: %ld bytes\n", amt);
#endif
rc = DosAllocMem(&buffer, amt, OBJ_TILE | PAG_READ | PAG_WRITE | PAG_COMMIT);
if (rc) {
fprintf((FILE *)usalp->errfile, "Cannot allocate buffer.\n");
return ((void *)0);
}
usalp->bufbase = buffer;
#ifdef DEBUG
fprintf((FILE *)usalp->errfile, "Buffer allocated at: 0x%x\n", usalp->bufbase);
#endif
/* Lock memory */
if (init_buffer(usalp->bufbase))
return (usalp->bufbase);
fprintf((FILE *)usalp->errfile, "Cannot lock memory buffer.\n");
return ((void *)0); /* Error */
}
示例12: Log_PrintLogMessage
// Message - сообщение.
VOID Log_PrintLogMessage( PCHAR Message )
{
// Отводим память для текста.
PCHAR Window_text = NULL; INT Length = 65536;
if( DosAllocMem( (PPVOID) &Window_text, Length, PAG_ALLOCATE ) != NO_ERROR ) return;
// Узнаем текст в поле ввода.
HWND Field = Log_LogWindow(); WinQueryWindowText( Field, Length, Window_text );
// Добавляем сообщение в поле ввода.
strcat( Window_text, Message ); strcat( Window_text, "\n" );
WinEnableWindowUpdate( Field, 0 );
WinSetWindowText( Field, Window_text );
WinEnableWindowUpdate( Field, 1 );
// Освобождаем память.
DosFreeMem( Window_text ); Window_text = NULL;
// Запоминаем, что поле ввода изменено.
Log.RTSettings.Field_is_changed = 1;
// Возврат.
return;
}
示例13: prc16ForEachProcess
ULONG prc16ForEachProcess(PFNWP pfnwpCallback, HWND hwnd, ULONG ulMsg, MPARAM mp1)
{
ULONG ulrc = 0;
PQPROCSTAT16 pps;
PQPROCESS16 pProcess;
PRCPROCESS prcp;
if (!DosAllocMem((PVOID*)&pps,
BUF_SIZE,
PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_TILE))
{
if (!DosQProcStatus(pps, BUF_SIZE))
for ( pProcess = (PQPROCESS16)PTR(pps->ulProcesses, 0);
pProcess->ulType != 3;
pProcess = (PQPROCESS16)PTR(pProcess->ulThreadList,
pProcess->usThreads * sizeof(QTHREAD16))
)
{
if (pfnwpCallback)
{
prcReport16(pProcess, &prcp);
(*pfnwpCallback)(hwnd, ulMsg, mp1, &prcp);
}
ulrc++;
}
DosFreeMem(pps);
}
return ulrc;
}
示例14: GetExportFilterStruct
XBitmapFilter* XBitmap :: GetExportFilterStruct (const char* filename) {
XBitmapFilter* filter;
XBitmapFilter dummy;
dummy.cbFix = 0;
CheckFilterProfile ();
XResourceLibrary* lib = new XResourceLibrary ("OOLGLIB");
XGLibProcFltInit* func = (XGLibProcFltInit*) lib->LoadFunction ("OOL_GLIB_EXP_INIT");
DosSleep(100);
if (NULL != func) {
ULONG rc;
if (0 == (rc = func (filename, __XBMFProfile__, NULL, 0)))
OOLThrow (GetLastErrorMessage (lib, &rc, &dummy), rc);
DosAllocMem ((PPVOID) &filter, rc, PAG_READ | PAG_WRITE | PAG_COMMIT);
filter->cbFix = rc;
filter->hab = XApplication :: GetApplication ()->GetAnchorBlock ();
if (BFE_OK != (rc = func (filename, __XBMFProfile__, filter, 0)))
OOLThrow (GetLastErrorMessage (lib, &rc, filter), rc);
lib->UnLoadFunction ((PFNWP) func);
} else {
ULONG error = WinGetLastError (XApplication :: GetApplication ()->GetAnchorBlock ());
OOLThrow("Could not load function \"OOL_GLIB_EXP_INIT\" from library \"OOLGLIB.DLL\".", error);
}
delete lib;
return filter;
}
示例15: copyaudio
int copyaudio(HMMIO hmmiofrom, HMMIO hmmioto, LONG Bytes)
{
// method allocates a buffer and does a standard copy from from to to
PCHAR pAudio = NULL;
DosAllocMem((void **) &pAudio,COPYSIZE,PAG_WRITE | PAG_COMMIT);
assert(pAudio!=NULL);
long BytesRead,BytesWritten;
long bytes_to_copy = Bytes;
do
{
if (bytes_to_copy > COPYSIZE)
{
//
// now read the FIRST file
BytesRead = mmioRead(hmmiofrom,(PCHAR)pAudio,COPYSIZE);
bytes_to_copy -= BytesRead;
}
else
{
BytesRead = mmioRead(hmmiofrom,(PCHAR)pAudio,bytes_to_copy);
bytes_to_copy -= BytesRead;
}
cout << " Read " << BytesRead << " from source file, " << bytes_to_copy << " left " << endl;
//
// write the new file
BytesWritten = mmioWrite(hmmioto,(PCHAR)pAudio,BytesRead);
assert(BytesRead==BytesWritten);
}
while(bytes_to_copy!=0);
DosFreeMem(pAudio);
return 0;
}