memset

zeroing derived struct using memset

倾然丶 夕夏残阳落幕 提交于 2019-12-19 11:26:51
问题 I want to zero out all members of a derived structure. There are hundreds of members and more are added every once in a while so I feel that initializing them explicitly is error-prone. The structures have no virtual functions and all the member fields are built-in. However, they are not POD by virtue of having non-trivial constructors. Apart from the standard frowning on the practice, do you see any issues with the following? struct Base { // Stuff }; struct Derived : public Base { //

zeroing derived struct using memset

强颜欢笑 提交于 2019-12-19 11:26:37
问题 I want to zero out all members of a derived structure. There are hundreds of members and more are added every once in a while so I feel that initializing them explicitly is error-prone. The structures have no virtual functions and all the member fields are built-in. However, they are not POD by virtue of having non-trivial constructors. Apart from the standard frowning on the practice, do you see any issues with the following? struct Base { // Stuff }; struct Derived : public Base { //

NOIP经典基础模板总结

时光总嘲笑我的痴心妄想 提交于 2019-12-18 18:54:32
date: 20180820 spj: 距离NOIP还有81天 目录 STL模板: priority_queue 的用法:重载<,struct cmp queue 的用法 stack 的用法 vector的用法 map和set的用法 * 遍历容器中得所有元素 dequeue双端队列的用法 基础数论模板: gcd ex_gcd 求phi():筛选法、定义法 筛选法求质数 判断质数的一般方法 快速幂 矩阵快速幂 求逆元的方法(递推式、快速幂、ex_gcd) 卢卡斯定理的实现 组合数朴素公式 组合数递推式(杨辉三角) 组合数取模 二项式定理 n的正约数个数(唯一分解定理的推导) ST表 裴蜀定理 高精度计算+-* *二项式反演 *离散概率 图论模板: floyd求最短路求最小环、图的传递闭包 spfa求最短路、dijkstra堆优化求最短路 kosaraju算法求强联通分量 tarjan求强联通分量 最小生成树 倍增LCA、tarjan LCA 并查集(启发式) 前向星存图 KM求最优匹配、匈牙利算法求最大匹配 FF算法求最大流 *最小费用最大流 树上Hash 数据结构模板: 树状数组模板(区间最大最小和) 线段树模板(区间最大最小和) 字典树(STL实现) 实数二分,整数二分答案 *线性基 字符串模板: 字符串哈希Hash(字符串必备) *KMP算法初步 *AC自动机 说明:打

Is there analog of memset in go?

萝らか妹 提交于 2019-12-17 19:32:55
问题 In C++ I can initialize an array with some value using memset: const int MAX = 1000000; int is_prime[MAX] memset(is_prime, 1, sizeof(is_prime)) What memset does, crudely can be described as filling the array with some value, but doing this really really fast. In go I can do is_prime := make([]int, 1000000) , but this will create a slice with all 0, in the similar manner I can use new([1000000]int) , but nothing will allow me to create an array/slice with all 1 or any other non-zero element.

[学习笔记]网络流24题

落花浮王杯 提交于 2019-12-17 19:11:03
不按24题的顺序,按我做题的顺序 1、飞行员配对方案问题 建个图,跑遍匈牙利,让飞行员给其对应的飞机连一条边 #include <bits/stdc++.h> using namespace std; const int maxn=10000+10; int n,m,e,head[maxn],to[maxn<<1],nxt[maxn<<1],vis[maxn],tot,ans,match[maxn]; inline void add(int x,int y){ to[++tot]=y; nxt[tot]=head[x]; head[x]=tot; } int dfs(int x){ for(int i=head[x];i;i=nxt[i]){ int y=to[i]; if(!vis[y]){ vis[y]=1; if(!match[y]||dfs(match[y])){ match[y]=x;return 1; } } } return 0; } int main() { scanf("%d%d",&n,&m); int x,y;scanf("%d%d",&x,&y); while(x!=-1&&y!=-1){ if(x<=n&&y<=n+m) add(x,y); scanf("%d%d",&x,&y); } for(int i=1;i<=n;i++){ memset(vis,0

矿场搭建(codevs 1996)

瘦欲@ 提交于 2019-12-17 06:24:56
题目描述 Description 煤矿工地可以看成是由隧道连接挖煤点组成的无向图。为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口处。于是矿主决定在某些挖煤点设立救援出口,使得无论哪一个挖煤点坍塌之后,其他挖煤点的工人都有一条道路通向救援出口。 请写一个程序,用来计算至少需要设置几个救援出口,以及不同最少救援出口的设置方案总数。 输入描述 Input Description 输入文件有若干组数据,每组数据的第一行是一个正整数N(N≤500),表示工地的隧道数,接下来的N 行每行是用空格隔开的两个整数S 和T,表示挖煤点S 与挖煤点T 由隧道直接连接。输入数据以0 结尾。 输出描述 Output Description 输入文件中有多少组数据,输出文件中就有多少行。每行对应一组输入数据的结果。其中第i 行以Case i: 开始(注意大小写,Case 与i 之间有空格,i 与:之间无空格,:之后有空格),其后是用空格隔开的两个正整数,第一个正整数表示对于第i 组输入数据至少需要设置几个救援出口,第二个正整数表示对于第i 组输入数据不同最少救援出口的设置方案总数。输入数据保证答案小于2^64。输出格式参照以下输入输出样例。 样例输入 Sample Input 9 1 3 4 1 3 5 1 2 2 6 1 5 6 3 1 6 3 2 6 1 2 1 3 2 4

Erasing sensitive information from memory

梦想的初衷 提交于 2019-12-13 15:14:27
问题 After reading this question I'm curious how one would do this in C. When receiving the information from another program, we probably have to assume that the memory is writable. I have found this stating that a regular memset maybe optimized out and this comment stating that memsets are the wrong way to do it. 回答1: The example you have provided is not quite valid: the compiler can optimize out a variable setting operation when it can detect that there are no side effects and the value is no

udp socket programming file transfer

泪湿孤枕 提交于 2019-12-12 19:59:51
问题 Server Side Code......... #include<stdio.h> #include<string.h> #include<stdlib.h> #include<arpa/inet.h> #include<sys/socket.h> #define BUFLEN 503 #define PORT 8885 void die(char *s) { perror(s); exit(1); } int main(void) { struct sockaddr_in si_me, si_other; int s, i,j, slen = sizeof(si_other) , recv_len; char buf[BUFLEN]; if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { die("socket"); } memset((char *) &si_me, '1', sizeof(si_me)); //printf("%d",si_me); si_me.sin_family = AF_INET; si

Is -1 a valid pointer address [duplicate]

瘦欲@ 提交于 2019-12-12 13:54:34
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Can a pointer (address) ever be negative? I'm considering initialising a structure to all -1s with memset(since it uses no signed numbers and zero is a valid value). Is -1 a valid pointer adress? and are there any other problems with my idea? note: platform is linux/gcc/x86 P.S. I'm trying to initialize a struct that is not all pointers and where zero is valid to all invalid like values so I can optionally do

Initializing a float array with memset

≯℡__Kan透↙ 提交于 2019-12-12 09:35:06
问题 This is the code that I want to try to write: #include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <malloc.h> int main(int argc, char *argv[]) { float arry[3] = {0}; memset(arry, (int) 10.0, 3*sizeof(float)); return 0; } My problem is that I want to see if it's possible to use memset to make every entry of an array to be a number other than 0. However, After stepping through that line, the array contents change to a very small number (0). I wonder what I'm