当前位置: 首页>>代码示例>>C++>>正文


C++ AllocateMemory函数代码示例

本文整理汇总了C++中AllocateMemory函数的典型用法代码示例。如果您正苦于以下问题:C++ AllocateMemory函数的具体用法?C++ AllocateMemory怎么用?C++ AllocateMemory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了AllocateMemory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CopyWideString

DWORD CopyWideString(
    IN _In_ LPWSTR pSrcWString,
    OUT _Out_ LPWSTR *pDestWString)
{
    DWORD retCode = NO_ERROR;
    HRESULT hr = S_OK;
    size_t dwStringLength = 0;
    LPWSTR pTempString = NULL;

    *pDestWString = NULL;

    // Nothing to copy
    if(!pSrcWString)
        goto Cleanup;

    hr = StringCbLengthW(pSrcWString, (size_t)(STRSAFE_MAX_CCH * sizeof(wchar_t)), &dwStringLength);
    if (FAILED(hr))
    {
        retCode = HRESULT_CODE(hr);
        goto Cleanup;
    }

    // StringCbLengthW - returns the length of string in bytes (excluding the null character).
    // StringCbCopyW expects the length of string in bytes (including the null character).
    dwStringLength += sizeof(wchar_t);
    retCode = AllocateMemory((DWORD)dwStringLength, (PVOID *)&pTempString);
    if(retCode != NO_ERROR)
    {
        goto Cleanup;
    }

    hr = StringCbCopyW((LPTSTR)pTempString, dwStringLength, pSrcWString);
    if (FAILED(hr))
    {
        retCode = HRESULT_CODE(hr);
        goto Cleanup;
    }

    //
    // Set the OUT parameter
    //
    *pDestWString = pTempString;

Cleanup:
    if((retCode != NO_ERROR) && (pTempString != NULL))
        FreeMemory((PVOID *)&pTempString);
    pTempString = NULL;
    return retCode;
}
开发者ID:9578577,项目名称:Windows-classic-samples,代码行数:49,代码来源:EapHostCommon.cpp

示例2: FAIL_RETURN

UPK_STATUS
NitroPlus::Open(
    PCWSTR FileName
)
{
    PVOID                   EntryBuffer;
    LARGE_INTEGER           BytesRead;
    NTSTATUS                Status;
    NITRO_PLUS_NPA_HEADER   Header;

    Status = m_File.Open(FileName);
    FAIL_RETURN(Status);

    Status = m_File.Read(&Header, sizeof(Header), &BytesRead);
    FAIL_RETURN(Status);

    if (
        BytesRead.LowPart != sizeof(Header) ||
        (*(PULONG)Header.Signature & 0x00FFFFFF) != NPA_HEADER_MAGIC
       )
    {
        return STATUS_UNSUCCESSFUL;
    }

    switch (Header.Version)
    {
        case NPA_GCLX_VERSION:
            break;

        default:
            return STATUS_UNSUCCESSFUL;
    }

    EntryBuffer = AllocateMemory(Header.EntrySize);
    if (EntryBuffer == NULL)
        return STATUS_INSUFFICIENT_RESOURCES;

    Status = m_File.Read(EntryBuffer, Header.EntrySize, &BytesRead);
    FAIL_RETURN(Status);

    if (BytesRead.LowPart != Header.EntrySize)
        return STATUS_UNSUCCESSFUL;

    Status = InitIndex(EntryBuffer, &Header);

    FreeMemory(EntryBuffer);

    return Status;
}
开发者ID:Emiyasviel,项目名称:Arianrhod,代码行数:49,代码来源:nitroplus.cpp

示例3: LoadBofName

Bool LoadBofName(char *fname)
{
   FILE *f = fopen(fname, "rb");
	if (f == NULL)
   {
      eprintf("LoadBofName can't open %s\n", fname);
		return False;
   }

   for (int i = 0; i < BOF_MAGIC_LEN; ++i)
   {
      unsigned char c;
      if (fread(&c, 1, 1, f) != 1 || c != magic_num[i])
      {
         eprintf("LoadBofName %s is not in BOF format\n", fname);
         fclose(f);
         return False;
      }
   }
   
   int version;
   if (fread(&version, 1, 4, f) != 4 || version != 5)
	{
		eprintf("LoadBofName %s can't understand bof version != 5\n",fname);
      fclose(f);
		return False;
	}
   
   // Go back to start of file and read the whole thing into memory.
   fseek(f, 0, SEEK_SET);
   
   struct stat st;
   stat(fname, &st);
   int file_size = st.st_size;

	char *ptr = (char *)AllocateMemory(MALLOC_ID_LOADBOF,file_size);
   if (fread(ptr, 1, file_size, f) != file_size)
   {
      fclose(f);
      return False;
   }

   fclose(f);

	AddFileMem(fname,ptr,file_size);
	
	return True;
}
开发者ID:Koveras,项目名称:Meridian59,代码行数:48,代码来源:loadkod.c

示例4: CreateStringWithLen

int CreateStringWithLen(char *buf,int len)
{
   int string_id;
   string_node *snod;
   
   /* note:  new_str is NOT null-terminated */
   string_id = AllocateString();
   snod = GetStringByID(string_id);

   snod->data = (char *)AllocateMemory(MALLOC_ID_STRING,len+1);
   memcpy(snod->data,buf,len);
   snod->len_data = len;
   snod->data[snod->len_data] = '\0';
   
   return string_id;
}
开发者ID:Koveras,项目名称:Meridian59,代码行数:16,代码来源:string.c

示例5: num_rows_

TripletSparseMatrix::TripletSparseMatrix(int num_rows,
                                         int num_cols,
                                         int max_num_nonzeros)
    : num_rows_(num_rows),
      num_cols_(num_cols),
      max_num_nonzeros_(max_num_nonzeros),
      num_nonzeros_(0),
      rows_(NULL),
      cols_(NULL),
      values_(NULL) {
  // All the sizes should at least be zero
  CHECK_GE(num_rows, 0);
  CHECK_GE(num_cols, 0);
  CHECK_GE(max_num_nonzeros, 0);
  AllocateMemory();
}
开发者ID:hanjianwei,项目名称:ACG-Tracker-Demo,代码行数:16,代码来源:triplet_sparse_matrix.cpp

示例6: InitAccount

void InitAccount(void)
{
   accounts = NULL;
   next_account_id = 1;

   console_account = &console_account_node;
   console_account->account_id = 0;
   console_account->name = ConfigStr(CONSOLE_ADMINISTRATOR);
   console_account->password = (char *)AllocateMemory(MALLOC_ID_ACCOUNT,1);
   console_account->password[0] = 0;

   console_account->type = ACCOUNT_ADMIN;
   console_account->last_login_time = 0;
   console_account->suspend_time = 0;
   console_account->credits = 0;
}
开发者ID:AlleyCat1976,项目名称:Meridian59_103,代码行数:16,代码来源:account.c

示例7: AllocateObject

int AllocateObject(int class_id)
{
   int old_objects;
   class_node *c;

   c = GetClassByID(class_id);
   if (c == NULL)
   {
      eprintf("AllocateObject can't find class id %i\n",class_id);
      return INVALID_OBJECT;
   }

   if (num_objects == max_objects)
   {
      old_objects = max_objects;
      max_objects = max_objects * 2;
      objects = (object_node *)
	 ResizeMemory(MALLOC_ID_OBJECT,objects,old_objects*sizeof(object_node),
		      max_objects*sizeof(object_node));
      lprintf("AllocateObject resized to %i objects\n",max_objects);
   }

   objects[num_objects].object_id = num_objects;
   objects[num_objects].class_id = class_id;
   objects[num_objects].deleted = False;
   objects[num_objects].num_props = 1 + c->num_properties;
   objects[num_objects].p = (prop_type *)AllocateMemory(MALLOC_ID_OBJECT_PROPERTIES,
							sizeof(prop_type)*(1+c->num_properties));

   if (ConfigBool(DEBUG_INITPROPERTIES))
   {
      int i;
      prop_type p;

      p.id = 0;
      p.val.v.tag = TAG_INVALID;
      p.val.v.data = 0;

      for (i = 0; i < (1+c->num_properties); i++)
      {
	 objects[num_objects].p[i] = p;
      }
   }

   return num_objects++;
}
开发者ID:AlleyCat1976,项目名称:Meridian59_103,代码行数:46,代码来源:object.c

示例8: CreateAccountFromSMTPMail

void CreateAccountFromSMTPMail(smtp_node *smtp)
{
#ifdef SMTP_TEST
	return;
#else
	
	int len_buf;
	char *buf;
	string_list *sl;
	
	/* put mail into buffer, than analyze, then free buffer */
	
	len_buf = 0;
	sl = smtp->data;
	while (sl != NULL)
	{
		len_buf += strlen(sl->str);
		sl = sl->next;
	}
	
	buf = (char *) AllocateMemory(MALLOC_ID_SMTP,len_buf+1);
	len_buf = 0;
	
	sl = smtp->data;
	while (sl != NULL)
	{
		strcpy(buf+len_buf,sl->str);
		len_buf += strlen(sl->str);
		sl = sl->next;
	}
	
	if (strcmp(smtp->forward_path->str,ConfigStr(EMAIL_ACCOUNT_CREATE_NAME)) == 0)
	{
		CreateAccountFromBuffer(buf);
	}
	else
	{
		if (strcmp(smtp->forward_path->str,ConfigStr(EMAIL_ACCOUNT_DELETE_NAME)) == 0)
			DeleteAccountFromBuffer(buf);
	}
	
	FreeMemory(MALLOC_ID_SMTP,buf,len_buf+1);
#endif
}
开发者ID:Shaijan,项目名称:Meridian59,代码行数:44,代码来源:smtpserv.c

示例9: CreateQueueHead

PQUEUE_HEAD
CreateQueueHead(PEHCI_HOST_CONTROLLER hcd)
{
    PQUEUE_HEAD CurrentQH;
    ULONG PhysicalAddress , i;
    KIRQL OldIrql;

    KeAcquireSpinLock(&hcd->Lock, &OldIrql);
    CurrentQH = (PQUEUE_HEAD)AllocateMemory(hcd, sizeof(QUEUE_HEAD), &PhysicalAddress);
    RtlZeroMemory(CurrentQH, sizeof(QUEUE_HEAD));

    ASSERT(CurrentQH);
    CurrentQH->PhysicalAddr = PhysicalAddress;
    CurrentQH->HorizontalLinkPointer = TERMINATE_POINTER;
    CurrentQH->AlternateNextPointer = TERMINATE_POINTER;
    CurrentQH->NextPointer = TERMINATE_POINTER;

    /* 1 for non high speed, 0 for high speed device */
    CurrentQH->EndPointCharacteristics.ControlEndPointFlag = 0;
    CurrentQH->EndPointCharacteristics.HeadOfReclamation = FALSE;
    CurrentQH->EndPointCharacteristics.MaximumPacketLength = 64;

    /* Set NakCountReload to max value possible */
    CurrentQH->EndPointCharacteristics.NakCountReload = 0xF;

    /* Get the Initial Data Toggle from the QEDT */
    CurrentQH->EndPointCharacteristics.QEDTDataToggleControl = FALSE;

    /* High Speed Device */
    CurrentQH->EndPointCharacteristics.EndPointSpeed = QH_ENDPOINT_HIGHSPEED;

    CurrentQH->EndPointCapabilities.NumberOfTransactionPerFrame = 0x03;

    CurrentQH->Token.DWord = 0;
    CurrentQH->NextQueueHead = NULL;
    CurrentQH->PreviousQueueHead = NULL;
    for (i=0; i<5; i++)
        CurrentQH->BufferPointer[i] = 0;

    CurrentQH->Token.Bits.InterruptOnComplete = FALSE;

    KeReleaseSpinLock(&hcd->Lock, OldIrql);
    return CurrentQH;
}
开发者ID:HBelusca,项目名称:NasuTek-Odyssey,代码行数:44,代码来源:hwiface.c

示例10: initializeTestData

void initializeTestData()
{
  root = AllocateMemory(1);
  struct tree *left1 = AllocateMemory(2);
  struct tree *left11 = AllocateMemory(4);
  struct tree *left12 = AllocateMemory(5);
  struct tree *right1 = AllocateMemory(3);
  struct tree *right11 = AllocateMemory(6);
  struct tree *right12 = AllocateMemory(7);
  root->left = left1;
  root->right=right1;
  left1->left=left11;
  left1->right=left12;
  right1->left=right11;
  right1->right=right12;
  
}   
开发者ID:batraman,项目名称:sandbox,代码行数:17,代码来源:TreeSearch.c

示例11: input_stream

    void Kernel::CreateProcess(const std::string &name)
    {
        if (_last_issued_process_id == std::numeric_limits<Process::process_id_type>::max()) {
            std::cerr << "Kernel: failed to create a new process. The maximum number of processes has been reached." << std::endl;
        } else {
            std::ifstream input_stream(name, std::ios::in | std::ios::binary);
            if (!input_stream) {
                std::cerr << "Kernel: failed to open the program file." << std::endl;
            } else {
                MMU::ram_type ops;

                input_stream.seekg(0, std::ios::end);
                auto file_size = input_stream.tellg();
                input_stream.seekg(0, std::ios::beg);
                ops.resize(static_cast<MMU::ram_size_type>(file_size) / 4);

                input_stream.read(reinterpret_cast<char *>(&ops[0]), file_size);

                if (input_stream.bad()) {
                    std::cerr << "Kernel: failed to read the program file." << std::endl;
                } else {
					MMU::ram_size_type new_memory_position = AllocateMemory(ops.size()); // TODO: allocate memory for the process (AllocateMemory)
                    if (new_memory_position == -1) {
                        std::cerr << "Kernel: failed to allocate memory." << std::endl;
                    } else {
                        std::copy(ops.begin(), ops.end(), (machine.mmu.ram.begin() + new_memory_position));

                        Process process(_last_issued_process_id++, new_memory_position,
                                                                   new_memory_position + ops.size());

                        // Old sequential allocation
                        //
                        // std::copy(ops.begin(), ops.end(), (machine.memory.ram.begin() + _last_ram_position));
                        //
                        // Process process(_last_issued_process_id++, _last_ram_position,
                        //                                            _last_ram_position + ops.size());
                        //
                        // _last_ram_position += ops.size();
                    }
                }
            }
        }
    }
开发者ID:vidanissa,项目名称:os_Project_Full,代码行数:43,代码来源:kernel.cpp

示例12: AllocateMemory

//*****************************************************************************
// Called to read the data into allocated memory and release the backing store.
//  Only available on read-only data.
//*****************************************************************************
HRESULT 
StgIO::LoadFileToMemory()
{
    HRESULT hr;
    void   *pData;          // Allocated buffer for file.
    ULONG   cbData;         // Size of the data.
    ULONG   cbRead = 0;     // Data actually read.
    
    // Make sure it is a read-only file.
    if (m_fFlags & DBPROP_TMODEF_WRITE)
        return E_INVALIDARG;
    
    // Try to allocate the buffer.
    cbData = m_cbData;
    pData = AllocateMemory(cbData);
    IfNullGo(pData);
    
    // Try to read the file into the buffer.
    IfFailGo(Read(pData, cbData, &cbRead));
    if (cbData != cbRead)
    {
        _ASSERTE_MSG(FALSE, "Read didn't succeed.");
        IfFailGo(CLDB_E_FILE_CORRUPT);
    }
    
    // Done with the old data.
    Close();
    
    // Open with new data.
    hr = Open(NULL /* szName */, STGIO_READ, pData, cbData, NULL /* IStream* */, NULL /* lpSecurityAttributes */);
    _ASSERTE(SUCCEEDED(hr)); // should not be a failure code path with open on buffer.
    
    // Mark the new memory so that it will be freed later.
    m_pBaseData = m_pData;
    m_bFreeMem = true;
    
ErrExit:
    if (FAILED(hr) && pData)
       FreeMemory(pData);
    
    return hr;
} // StgIO::LoadFileToMemory
开发者ID:A-And,项目名称:coreclr,代码行数:46,代码来源:stgio.cpp

示例13: INHERITED

GrVkSubHeap::GrVkSubHeap(const GrVkGpu* gpu, uint32_t memoryTypeIndex,
                         VkDeviceSize size, VkDeviceSize alignment)
    : INHERITED(size, alignment)
    , fGpu(gpu)
    , fMemoryTypeIndex(memoryTypeIndex) {

    VkMemoryAllocateInfo allocInfo = {
        VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,      // sType
        NULL,                                        // pNext
        size,                                        // allocationSize
        memoryTypeIndex,                             // memoryTypeIndex
    };

    VkResult err = GR_VK_CALL(gpu->vkInterface(), AllocateMemory(gpu->device(),
                              &allocInfo,
                              nullptr,
                              &fAlloc));
    if (VK_SUCCESS != err) {
        this->reset();
    }
}
开发者ID:rlugojr,项目名称:skia,代码行数:21,代码来源:GrVkMemory.cpp

示例14: AddFileMem

/* add a filename and mapped ptr to the list of loaded files */
void AddFileMem(char *fname,char *ptr,int size)
{
	loaded_bof_node *lf;
	
	/* make new loaded_file node */
	lf = (loaded_bof_node *)AllocateMemory(MALLOC_ID_LOADBOF,sizeof(loaded_bof_node));
	strcpy(lf->fname,fname);
	lf->mem = ptr;
	lf->length = size;
	
	/* we store the fname so the class structures can point to it, but kill the path */
	
	if (strrchr(lf->fname,'\\') == NULL)
		FindClasses(lf->mem,lf->fname); 
	else
		FindClasses(lf->mem,strrchr(lf->fname,'\\')+1); 
	
	/* add to front of list */
	lf->next = mem_files;
	mem_files = lf;
}
开发者ID:Koveras,项目名称:Meridian59,代码行数:22,代码来源:loadkod.c

示例15: AssociateUser

Bool AssociateUser(int account_id,int object_id)
{
   user_node *u;

   u = users;
   while (u != NULL)
   {
      if (u->object_id == object_id)
	 return False;
      u = u->next;
   }

   u = (user_node *)AllocateMemory(MALLOC_ID_USER,sizeof(user_node));
   u->account_id = account_id;
   u->object_id = object_id;

   u->next = users;
   users = u;

   return True;
}
开发者ID:AlleyCat1976,项目名称:Meridian59_103,代码行数:21,代码来源:user.c


注:本文中的AllocateMemory函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。