sizeof

'%d' expects argument of type 'int', but argument 2 has type 'long unsigned int' [-Wformat=] [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: How can one print a size_t variable portably using the printf family? 12 answers I keep getting compile warnings but I don't know how to fix it: '%d' expects argument of type 'int', but argument 2 has type 'long unsigned int' [ The program runs fine but I still get the compile warnings: /* Sizeof.c--Program to tell byte size of the C variable */ #include int main(void) { printf("\nA Char is %d bytes", sizeof( char )); printf("\nAn int is %d bytes", sizeof( int )); printf("\nA short is %d bytes",

Efficient implementation of binary heaps

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm looking for information on how to implement binary heaps efficiently. I feel like there should be a nice article somewhere about implementing heaps efficiently, but I haven't found one. In fact I've been unable to find any resources on the matter of efficient implementation beyond the basics like storing the heap in an array. I'm looking for techniques for making a fast binary heap beyond the ones I describe below. I've already written a C++ implementation that is faster than Microsoft Visual C++'s and GCC's std::priority_queue or using

memcpy函数的用法以及实现一个memcpy函数

不羁的心 提交于 2019-12-03 02:33:21
memcpy的用法 在项目中经常用到 memcpy 来实现内存的拷贝工作,如下代码片段 memcpy( pData, m_pSaveData_C, iSize * sizeof( unsigned short ) ); memcpy 的函数原型为: void * memcpy ( void * destination, const void * source, size_t num ); memcpy函数的功能是从源内存地址的起始位置开始拷贝若干个 字节 到目标内存地址中,即从源source中拷贝num个 字节 到目标destin中。 示例代码 int main() { vector<int> vec; vector<int> vec1; vec.push_back(10); vec.push_back(100); vec1.resize(vec.size()); memcpy(vec1.data(),vec.data(),vec.size() * sizeof(int)); for (vector<int>::iterator it = vec1.begin();it != vec1.end();it++) { cout << *it; } char myname[] = "Pierre dee Fermat"; memcpy(person.name,myname,strlen

How to get the size of a JavaScript object?

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to know the size occupied by a JavaScript object. Take the following function: function Marks(){ this.maxMarks = 100; } function Student(){ this.firstName = "firstName"; this.lastName = "lastName"; this.marks = new Marks(); } Now I instantiate the student : var stud = new Student(); so that I can do stuff like stud.firstName = "new Firstname"; alert(stud.firstName); stud.marks.maxMarks = 200; etc. Now, the stud object will occupy some size in memory. It has some data and more objects. How do I find out how much memory the stud object

Get &#039;optimistic&#039; size of managed object in memory

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: First, I am aware of many posted questions covering the topic: 1 2 3 4 5 . The proposed approaches & why not: Marshal.SizeOf() 1 - does not work for managed types. GC.GetTotalMemory 1 2 - race condition prone. Serialization 1 2 3 4 - it's quite close, but automatic-fields can be problematic, as well as properties without public setter. Also, it's not optimal performance-wise. Code profiling using SOS 1 2 and other tools - great, but not for runtime. Due to padding and issues posted 1 2 3 , it appears, there is no optimal solution, rather

Why does sizeof(char + char) return 4?

匿名 (未验证) 提交于 2019-12-03 02:30:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What will printf write to the screen? I thought because sizeof(char)=1, that sizeof(a+b) will be also 1, but it turned out to be 4. I don't understand this, why does it write 4 if we are adding two chars? 回答1: In C language operands of almost all arithmetic operators are subjected to implicit conversions called usual arithmetic conversions or, in this case, integer promotions . Operands of type char are promoted to type int and the actual addition is performed within the domain of int (or unsigned int , depending on the properties of char on

strlen()与sizeof()

大城市里の小女人 提交于 2019-12-03 02:29:55
一、strlen() strlen()为计算字符串长度的函数,以‘\0’为字符串结束标志。注意:其传入参数必须是字符串指针(char*), 当传入的是数组名时,实际上数组退化成指针了。 二、sizeof() sizeof()为运算符,用于计算所分配给元素的内存大小,其返回结果类型为size_t。 来源: https://www.cnblogs.com/socks/p/11714347.html

2D Texture from 2D array CUDA

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to pass an Nx3 array to a kernel and read from it as in texture memory and write to a second array. Here is my simplified code with N=8: #include <cstdio> #include "handle.h" using namespace std; texture<float,2> tex_w; __global__ void kernel(int imax, float(*w)[3], float (*f)[3]) { int i = threadIdx.x; int j = threadIdx.y; if(i<imax) f[i][j] = tex2D(tex_w, i, j); } void print_to_stdio(int imax, float (*w)[3]) { for (int i=0; i<imax; i++) { printf("%2d %3.6f\t %3.6f\t %3.6f\n",i, w[i][0], w[i][1], w[i][2]); } } int main(void) {

calloc in Swift

匿名 (未验证) 提交于 2019-12-03 02:26:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: How do I transform the following ObjectiveC statements into SWIFT: UInt32 * pixels ; pixels = ( UInt32 *) calloc ( height * width , sizeof ( UInt32 )); I tried to do the following: var pixels : UInt32 pixels = ( UInt32 ) calloc ( height * width , sizeof ( UInt32 )) and I receive the error message: Int is not convertible to UInt and the (UInt32) Casting didn't work as well. Can someone give me some advice please? I am struggling a little bit with SWIFT still. Thank you. 回答1: Here's an easier way of allocating that array in swift:

virtual method table for multiple-inheritance

匿名 (未验证) 提交于 2019-12-03 02:24:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm reading this article " Virtual method table " Example in the above article: class B1 { public: void f0() {} virtual void f1() {} int int_in_b1; }; class B2 { public: virtual void f2() {} int int_in_b2; }; class D : public B1, public B2 { public: void d() {} void f2() {} // override B2::f2() int int_in_d; }; B2 *b2 = new B2(); D *d = new D(); In the article, the author introduces that the memory layout of object d is like this: d: D* d--> +0: pointer to virtual method table of D (for B1) +4: value of int_in_b1 B2* b2--> +8: pointer to