关于LocalAlloc的问题(回答给高分!!)

jgf_student 2004-11-25 09:04:41
在VC6.0的MFC appwizard环境中,调用LocalAlloc()函数时,运行时总通不过,调试时报错如下:
"0x10218253"指令引用的"0x00000000"内存.该内存不能为"read".
本人百思不得其解,请高手指教!
...全文
529 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
caicaiWu 2004-11-30
  • 打赏
  • 举报
回复
lpBuf1 = (LPBYTE)LocalAlloc(LPTR, nSize);
FlyYang 2004-11-30
  • 打赏
  • 举报
回复
GolbalAlloc 和 LocalAlloc 都不提倡使用
他们的速度都比较慢,而其功能较少
你看看MSDN吧
微软建议用heap functions
kilnut 2004-11-27
  • 打赏
  • 举报
回复

没用过
我都用GloablAlloc和GlobalReAlloc
qrlvls 2004-11-26
  • 打赏
  • 举报
回复

Platform SDK: Memory Management
Memory Management Functions

The following functions are used in memory management.

Function Description
CopyMemory Copies a block of memory from one location to another.
CreateMemoryResourceNotification Creates a memory resource notification object.
FillMemory Fills a block of memory with a specified value.
GetLargePageMinimum Retrieves the minimum size of a large page.
GetWriteWatch Retrieves the addresses of the pages that have been written to in a region of virtual memory.
GlobalMemoryStatus Obtains information about the system's current usage of both physical and virtual memory.
GlobalMemoryStatusEx Obtains information about the system's current usage of both physical and virtual memory.
IsBadCodePtr Determines whether the calling process has read access to the memory at the specified address.
IsBadReadPtr Verifies that the calling process has read access to the specified range of memory.
IsBadStringPtr Verifies that the calling process has read access to a range of memory pointed to by a string pointer.
IsBadWritePtr Verifies that the calling process has write access to the specified range of memory.
MoveMemory Moves a block of memory from one location to another.
QueryMemoryResourceNotification Retrieves the state of the specified memory resource object.
ResetWriteWatch Resets the write-tracking state for a region of virtual memory.
SecureZeroMemory Fills a block of memory with zeros.
ZeroMemory Fills a block of memory with zeros.


The following are the AWE functions.

Function Description
AllocateUserPhysicalPages Allocates physical memory pages to be mapped and unmapped within any AWE region of the process.
FreeUserPhysicalPages Frees physical memory pages previously allocated with AllocateUserPhysicalPages.
MapUserPhysicalPages Maps previously allocated physical memory pages at the specified address within an AWE region.
MapUserPhysicalPagesScatter Maps previously allocated physical memory pages at the specified address within an AWE region.

The following are the global and local functions. These functions are slower than other memory management functions and do not provide as many features. Therefore, new applications should use the heap functions. However, the global functions are still used with DDE and the clipboard functions.

Function Description
GlobalAlloc Allocates the specified number of bytes from the heap.
GlobalDiscard Discards the specified global memory block.
GlobalFlags Returns information about the specified global memory object.
GlobalFree Frees the specified global memory object.
GlobalHandle Retrieves the handle associated with the specified pointer to a global memory block.
GlobalLock Locks a global memory object and returns a pointer to the first byte of the object's memory block.
GlobalReAlloc Changes the size or attributes of a specified global memory object.
GlobalSize Retrieves the current size of the specified global memory object.
GlobalUnlock Decrements the lock count associated with a memory object.
LocalAlloc Allocates the specified number of bytes from the heap.
LocalDiscard Discards the specified local memory object.
LocalFlags Returns information about the specified local memory object.
LocalFree Frees the specified local memory object.
LocalHandle Retrieves the handle associated with the specified pointer to a local memory object.
LocalLock Locks a local memory object and returns a pointer to the first byte of the object's memory block.
LocalReAlloc Changes the size or the attributes of a specified local memory object.
LocalSize Returns the current size of the specified local memory object.
LocalUnlock Decrements the lock count associated with a memory object.


The following are the heap functions.

Function Description
GetProcessHeap Obtains a handle to the heap of the calling process.
GetProcessHeaps Obtains handles to all of the heaps that are valid for the calling process.
HeapAlloc Allocates a block of memory from a heap.
HeapCompact Attempts to compact a specified heap.
HeapCreate Creates a heap object.
HeapDestroy Destroys the specified heap object.
HeapFree Frees a memory block allocated from a heap.
HeapLock Attempts to acquire the lock associated with a specified heap.
HeapQueryInformation Retrieves information about the specified heap.
HeapReAlloc Reallocates a block of memory from a heap.
HeapSetInformation Sets heap information for the specified heap.
HeapSize Retrieves the size of a memory block allocated from a heap.
HeapUnlock Releases ownership of the lock associated with a specified heap.
HeapValidate Attempts to validate a specified heap.
HeapWalk Enumerates the memory blocks in a specified heap.

The following are the virtual memory functions.

Function Description
VirtualAlloc Reserves or commits a region of pages in the virtual address space of the calling process.
VirtualAllocEx Reserves or commits a region of pages in the virtual address space of the specified process.
VirtualFree Releases or decommits a region of pages within the virtual address space of the calling process.
VirtualFreeEx Releases or decommits a region of memory within the virtual address space of a specified process.
VirtualLock Locks the specified region of the process's virtual address space into physical memory.
VirtualProtect Changes the access protection on a region of committed pages in the virtual address space of the calling process.
VirtualProtectEx Changes the access protection on a region of committed pages in the virtual address space of the calling process.
VirtualQuery Provides information about a range of pages in the virtual address space of the calling process.
VirtualQueryEx Provides information about a range of pages in the virtual address space of the calling process.
VirtualUnlock Unlocks a specified range of pages in the virtual address space of a process.


Platform SDK Release: February 2003 What did you think of this topic?
Order a Platform SDK CD


qrlvls 2004-11-26
  • 打赏
  • 举报
回复
建议仔细阅读MSDN中有关内存分配的内容,对各种内存分配有详述
roger_ding 2004-11-26
  • 打赏
  • 举报
回复
Note The local functions are slower than other memory management functions and do not provide as many features. Therefore, new applications should use the heap functions.

所以用HeapAlloc替换LocalAlloc试试
kingzai 2004-11-26
  • 打赏
  • 举报
回复
用GolbalAlloc替换LocalAlloc试一下呢?
jgf_student 2004-11-26
  • 打赏
  • 举报
回复
代码如下,请各位高手不吝指教,本人不胜感激!!!!
//声明变量
int nSize;
LPBYTE lpBuf1, lpBuf2, lpBufOut;
HFILE hFile1, hFile2, hFileOut;
LPBITMAPINFO lpInfo;
HDC hDC;
int i;

//打开文件(bmp格式的图片)
hFile1 = _lopen("..//BMP//1.bmp",OF_READ);
hFile2 = _lopen("..//BMP//2.bmp",OF_READ);
hFileOut =_lcreat("..//BMP//out.bmp",0); //添加一个新文件

nSize = GetFileSize((HANDLE) hFile1, NULL); //读取hFile1(bmp图片)文件的大小
lpBuf1 = LocalAlloc(LPTR, nSize); //申请nSize大小的文件,就是在此处出错,申请失败,不知是何原因?
lpBuf2 = LocalAlloc(LPTR, nSize);
lpBufOut = LocalAlloc(LPTR, nSize);

_lread(hFile1, lpBuf1, nSize);
_lread(hFile2, lpBuf2, nSize);

_lclose(hFile1);
_lclose(hFile2);

memcpy(lpBufOut, lpBuf1, nSize);
hundlom 2004-11-25
  • 打赏
  • 举报
回复
"0x10218253"指令引用的"0x00000000"内存错误可能是引用错误,检查指针变量和其他变量是否初始化
kingzai 2004-11-25
  • 打赏
  • 举报
回复
replace LocalAlloc with GolbalAlloc
pleasehelpme 2004-11-25
  • 打赏
  • 举报
回复
gz
qrlvls 2004-11-25
  • 打赏
  • 举报
回复
那一部分的代码是怎样的
内容概要:本文针对无刷直流电机驱动的电子机械制动(EMB)执行器,建立了考虑Stribeck摩擦特性的非线性耦合动力学模型,并在Simulink环境中完成了系统级仿真分析。研究综合集成了电机动力学、齿轮传动机构与制动执行机构的动力学特性,构建了高保真的机电一体化系统模型。重点引入Stribeck摩擦模型以精确描述低速工况下执行器内部存在的静摩擦、粘滞摩擦与库仑摩擦之间的过渡行为,有效提升了系统在启停、反向运动等瞬态过程中的动态响应仿真精度。通过多工况仿真验证了模型的有效性,能够准确反映摩擦引起的爬行、滞后与定位误差等非线性现象,为EMB系统的高性能控制算法设计(如摩擦补偿、滑模控制)与结构优化提供了高可信度的仿真平台。; 适合人群:从事汽车电子制动系统、电机驱动控制、机电系统建模与仿真研究的研究生、科研人员及工程技术人员,需具备扎实的机械动力学、自动控制理论基础和MATLAB/Simulink仿真能力。; 使用场景及目标:①用于高精度电子机械制动系统的设计验证与性能预测;②为消除摩擦非线性影响的先进控制策略(如自适应控制、智能控制)提供精确的被控对象模型;③深入探究Stribeck摩擦等非线性因素对系统动态性能(如响应延迟、稳态误差)的作用机理; 阅读建议:读者应结合提供的Simulink模型文件,深入剖析Stribeck摩擦模块的数学实现与参数辨识方法,建议通过改变输入指令(如阶跃、正弦)和负载条件进行对比仿真,以直观理解非线性摩擦对系统动态特性的影响。

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧