sizeof

C# sizeof object pointer (SAFE context)

僤鯓⒐⒋嵵緔 提交于 2019-12-25 01:34:26
问题 Ok while sizeof(Myenum) and sizeof(int) works, I would like to use sizeof(object), but I don't want the size of the object, but the size of pointer... only for portability reason, I need to know if is a 64 bit pointer or 32 bit pointer, I can avoid using sizeof if is ok with conditional compilation, but I don't know if there are constants to check if we are on a 32 bit system instead of 64 bit Thanks for suggestions 回答1: Use IntPtr.Size . Reference : Simple way to check if you're on a 64-bit

Socket网络编程--简单Web服务器(2)

*爱你&永不变心* 提交于 2019-12-24 22:25:09
  上一小节通过阅读开源的Web服务器--tinyhttpd。大概知道了一次交互的请求信息和应答信息的具体过程。接下来我就自己简单的实现一个Web服务器。   下面这个程序只是实现一个简单的框架出来。这次先实现能够Accept客户端的请求。   简单创建web服务器   webserver.h 1 #include <iostream> 2 #include <string> 3 #include <string.h> 4 #include <stdio.h> 5 #include <stdlib.h> 6 #include <errno.h> 7 #include <sys/types.h> 8 #include <sys/socket.h> 9 #include <netinet/in.h> 10 #include <arpa/inet.h> 11 #include <unistd.h> 12 #include <pthread.h> 13 #include <thread>//使用c++11的多线程 14 15 using namespace std; 16 17 class WebServer 18 { 19 public: 20 WebServer(); 21 ~WebServer(); 22 int ServerInit(u_short port); 23 int

网络通信 --> socket通信

倖福魔咒の 提交于 2019-12-24 20:52:29
socket通信    socket是应用层与 TCP/IP协议族通信的中间软件抽象层,是一组接口。 工作原理如下:    具体过程 :服务器端先初始化s ocket,然后与端口绑定 (bind),对端口进行监听 (listen),调用 accept阻塞,等待客户端连接。在这时如果有个客户端初始化一个s ocket ,然后连接服务器 (connect),如果连接成功,这时客户端与服务器端的连接就建立了。客户端发送数据请求,服务器端接收请求并处理请求,然后把回应数据发送给客户端,客户端读取数据,最后关闭连接,一次交互结束。 socket属性 1.创建套接字   套接字的特性由三个属性确定:域(domain), 类型(type)和协议(protocol)。 int socket(int domain, int type, int protocol);     domain :指定socket的类型,一般为AF_INET;    type :是SOCK_STREAM 或SOCK_DGRAM,分别表示TCP连接和UDP连接;    protocol :通常赋值"0"。 socket()调用返回一个整型socket描述符,你可以在后面的调用使用它。 2.命名套接字 int bind(int sockfd, const struct sockaddr *addr, socklen_t

c++ sizeof() not returning correct size [duplicate]

廉价感情. 提交于 2019-12-24 19:29:17
问题 This question already has answers here : Why is sizeof(string) == 32? (6 answers) sizeof in c++ showing string size one less (4 answers) Closed 6 years ago . I'm trying to get the size of a string in my program, so then I can convert it into a char later using a loop, but the size that the program is returning is 5 numbers lesser than the actual size. Why would this be happening? std::string theFileName = fileNames[ curTab ]; int size = sizeof( theFileName ); When debugging my program, it

线性表

江枫思渺然 提交于 2019-12-24 19:06:18
阅读目录 一、线性表类型定义 二、顺序表 三、链表 四、总结 一、线性表类型定义 1.定义 线性表是n个数据元素的有限序列 2.基本操作 InitList(&L) #构造一个空的线性表L DestroyList(&L) #销毁线性表L ClearList(&L) #将L重置为空表 ListLength(L) #返回L中数据元素个数 GetItem(L,i,&e) #用e返回L中第i个数据元素的值 LocateElem(L,e,compare()) #返回L中第1个与e满足关系compare()的数据元素的位序。若这样的数据远古三不存在,则返回值为0 ListInsert(&L,i,e) #在L中第i个位置之前插入新的数据元素e,L的长度加1 ListDelete(&L,i,&e) #删除L的dii个数据元素,并用e返回其值,L的长度减1 二、顺序表 1.定义 线性表的顺序存储结构称为顺序表。 假设线性表的每个元素需占用l个存储单元,一般来说,线性表的第i个数据元素a i的存储位置为LOC(a i) = LOC(a 1) + (i-1)*l 2.实现 由于高级程序设计语言中的数组类型也有随机存取的特性,因此,通常都用数组来描述数据结构中的顺序存储结构。在此,由于线性表的长度可变,且所需最大存储空间随问题不同而不同,则在C语言中可用动态分配的一维数组 顺序开始为为1

what is the different with malloc_size and sizeof

只愿长相守 提交于 2019-12-24 14:34:13
问题 I am using Ojb-c, and I want to know the memory size of an object, but I got this, NSObject *obj = [[[NSObject alloc] init] autorelease]; NSLog(@"malloc size of myObject: %zd", malloc_size(obj)); NSLog(@"size of myObject: %zd", sizeof(obj)); malloc size of myObject: 16 size of myObject: 4 I know the sizeof(obj) is 4, because the pointer size on ios 32 is 4 bytes, what is the difference? But more than this, @interface TestObj : NSObject @property (nonatomic, retain) NSArray *arr; @property

sizeof(extern类型数组)

倖福魔咒の 提交于 2019-12-24 13:59:55
error: #70: incomplete type is not allowed 用sizeof计算数组大小,编译器提示不允许使用不完整的类型。在keil上编译直接报错,拿到vs2010上编译可以通过,但是结果始终为0. 折腾半天终于搞明白其中的原因,原因如下:   1.sizeof的计算发生在代码编译的时候;   2.extern是在链接的时候解析的。 所以extern数组的时候,在.C文件里面只知道有这么个东西,但是具体长啥样不知道,只有到链接的时候才能确定其大小。sizeof在编译的时候extern数组还没有链接,所以才会提示不允许使用不完整的类型。 解决方法:1.直接把变量定义在要用sizeof的文件中。      2.定义一个数组大小的宏。 来源: https://www.cnblogs.com/huhui/p/6913582.html

what's the size of std::tr1::array<int, 16> >

陌路散爱 提交于 2019-12-24 10:56:36
问题 I wonder how to get the size of std::tr1::array<int, 16> > ? is it just 16*sizeof(int) , which is how 16 byte? 回答1: Try sizeof(std::tr1::array<int, 16> >) 回答2: Yes, std::tr1::array is guaranteed to be an aggregate type that wraps the underlying raw array, which in fact you can access with the data() member function. And the size of a raw array is the number of elements times the size of one element. 来源: https://stackoverflow.com/questions/11854477/whats-the-size-of-stdtr1arrayint-16

Why the size of malloc-ed array and non-malloced array are different? [duplicate]

▼魔方 西西 提交于 2019-12-24 07:40:12
问题 This question already has answers here : Sizeof arrays and pointers (5 answers) Closed 3 years ago . #include<stdio.h> #include<stdlib.h> int main (int argc, char *argv[]) { int* arr1 = (int*)malloc(sizeof(int)*4); int arr2[4]; printf("%d \n", sizeof(arr1)); printf("%d \n", sizeof(arr2)); free(arr1); return 0; } Output 8 16 Why? 回答1: Arrays are not pointers. In your code, arr1 is a pointer, arr2 is an array. Type of arr1 is int * , whereas, arr2 is of type int [4] . So sizeof produces

gcc常用编译选项

☆樱花仙子☆ 提交于 2019-12-24 07:02:18
“-Wall”选项打开所有最常用到的编译警告,强烈建议打开,可以捕捉到许多在C编程中最常发生的错误。 “-o”选项来为可执行文件指定一个不同的输出文件。 “-c”用于把源码文件编译成对象文件。 对象文件包含的是机器码,其中任何对在其他文件中的函数(或变量)的内存地址的引用都留着没有被解析。这样就允许在互相之间不直接引用的情况下编译各个源代码文件。链接器在生成可执行文件时会填写这些还缺少的地址,然后把所有的对象文件组合在一起生成单个的可执行文件。当用“-c”来编译时,编译器会自动生成与源文件同名,但用“.o”来代替原来的扩展名的对象文件。 gcc使用链接器ld来施行链接,它是一个单独的程序。在GNU系统上用到的是GNU的链接器,即GNU ld。 通常,链接要快于编译----在一个有许多源文件的大型项目中,只重新编译那些被修改过的文件可以显著地节省时间。仅仅重编译项目中修改过的文件的过程可以用GNU Make来自动完成。 标准的系统库通常能在“/usr/lib”和“/lib”目录下,C标准库自身存放在“/usr/lib/libc.a”中,包含ANSI/ISO C标准指定的各个函数。其他库都需要显示或隐示指定。 “-lNAME”试图链接标准库目录下的文件名为“libNAME.a”中的对象文件。在大型程序中通常会用到很多“-l”选项,来链接象数学库,图形库和网络库。使用选项“-lNAME