我有以下课程:
class MyClass{
{
Run Code Online (Sandbox Code Playgroud)
和以下字符串:
string s="MyClass";
Run Code Online (Sandbox Code Playgroud)
如何使用字符串s获取类的类型:
Type t = typeof(MyClass); //but i need to use s instead.
Run Code Online (Sandbox Code Playgroud)
我已经尝试过了
Type type = Type.GetType(s); //the result is null
Run Code Online (Sandbox Code Playgroud) 无论多少; 你放在ac#代码行的末尾,编译器不会显示错误,并且
几乎所有其他语言(如c,c ++和java)的构建都是成功的......这是不允许的.
任何解释?
我正在使用VS08来构建/运行以下c ++代码:
#include <stdlib.h>
struct Header
{
int count;
}*lstHeader=NULL;
int main()
{
for(int i=0;i<10;i++)
{
lstHeader=(Header*)realloc(lstHeader,sizeof(Header)+i);
lstHeader[i].count=i;
}
return 1;
}
Run Code Online (Sandbox Code Playgroud)
并在运行后我得到以下VS异常:
Windows has triggered a breakpoint in MyProgram.exe.
This may be due to a corruption of the heap, which indicates a bug in
MyProgram.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while MyProgram.exe has focus.
The output window may have more diagnostic information.
Run Code Online (Sandbox Code Playgroud)
我试过malloc lstHeader而不是将它分配给NULL,但是同样的VS异常发生了,我无法想象y.
我有以下结构:
struct Node{
int *VC;
Node *Next;
};
Run Code Online (Sandbox Code Playgroud)
我的目标是创建指向一个指针的链接列表 int
我的问题是如何为内存分配内存Node.即
int* ptr = (int *) malloc(sizeof(int)*10);
//code to allocate memory for a new Node n
n->VC = ptr;
n->Next = null;
Run Code Online (Sandbox Code Playgroud)
然后我可能会这样做:
int *_ptr= (int *) malloc(sizeof(int)*10);
//code to allocate memory for a new Node c
c->VC= _ptr;
c->Next = null;
n->Next = c;
Run Code Online (Sandbox Code Playgroud) 我无法使用以下代码分配内存:
int *h_VC = (int *)malloc(sizeof(int)*SIZE); //SIZE is 19200
if(h_VC==NULL)
{
printf("Memory Not avaialble");
}
Run Code Online (Sandbox Code Playgroud)
我的代码在while循环中使用上面的块并运行了几次.我有8GB内存.我在运行代码的同时监视可用内存.
内存分配失败,虽然我剩下3GB的可用内存.
可能是什么问题呢?