小编Vir*_*cks的帖子

c ++通过引用和指针传递参数

在c ++中

class bar
{
    int i;
    char b;
    float d;
};

void foo ( bar arg );
void foo ( bar &arg );
void foo ( bar *arg );
Run Code Online (Sandbox Code Playgroud)

这是一个示例类/结构和函数,
我有一些Q.

  • 在'asm',大小,速度中传递参数的第一种和第二种方式之间有什么区别?
  • 在每种情况下如何将参数传递给函数foo(在指针的情况下我知道指针被推到堆栈上)
  • 在传递论据时,在效率方面(速度,大小,优势)哪个更好?
  • 什么是intel'asm'语法对应每种传递参数的方式?

我知道什么是"现代编译器和CPU无关紧要",但如果我们谈论旧CPU或编译器呢?

提前致谢

c++ size performance assembly arguments

26
推荐指数
1
解决办法
2万
查看次数

C++内存分配

使用C++时,如果有一个类:

class MyClass
{
    char memory1bye;
    int memory4bytes;
    int another4bytes;
};
Run Code Online (Sandbox Code Playgroud)

这个类在内存中总共使用9个字节...所以,如果我做了类似的事情:

MyClass *t1;
Run Code Online (Sandbox Code Playgroud)

这将为我提供Class的可用地址,但是它会分配9个字节吗?它会调用默认构造函数吗?或者我需要将这9个字节malloc给该类吗?如果那时我打电话给:

t1 = (MyClass *)new MyClass;
Run Code Online (Sandbox Code Playgroud)

是否会被视为内存泄漏?换句话说,旧地址会发生什么?

c++ memory-management

3
推荐指数
1
解决办法
2015
查看次数

c ++函数参数编辑

我正在进行内存分配/释放功能,
这很简单

inline void safedealloc ( void *mem )
{
     if ( mem ) { free( mem ); mem = NULL; }
}  
Run Code Online (Sandbox Code Playgroud)

它工作正常..然而,在使用它几次与程序后,
我注意到它在类似的东西中调用它

safedealloc( (char *)name );
safedealloc( (char *)name );
Run Code Online (Sandbox Code Playgroud)

导致错误.. 第一次调用后名称应该为null.但它没有,第二次使用无效指针ofc导致错误..为什么不将null分配给名称,因为它应该?

PS:使用malloc正确分配名称,并使用有效的大小和内容

c++ pointers arguments function

1
推荐指数
2
解决办法
139
查看次数

c ++代码缺点/专业

下面我有一个在我的大多数简单程序中运行的代码.
我想知道它是好还是坏......以及缺点/专业人士.

.
win32头文件: win32.h

// example of a not realated code to exaplin the question
// this header have all win32 includes like win/proces/stdarg/string ... etc
#include <windows.h>
#include <process.h>
#include <stdarg.h>
Run Code Online (Sandbox Code Playgroud)

主头文件: inc.h

//this file includes the following

//top : the windows header file
#include "win32.h" // include the win32.h header file 

//the extern define which is the question
//the first include cause the INCS to be defined 
//any include afterwards causes the DD to go from 'nothing' …
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
350
查看次数