|
|
back to boardWhare goes memory? Posted by Lomir 16 Feb 2007 23:50 I use: vector<int> v[1000]; Empty programm "eates" 100kb of memory. Vector has special mem allocation (allocates everytime then needed only space for 15 elements). So maxinun there are only 15000 unseed elements. So (100000+15000)*4=460000bytes = 450kb + 100 = 550kb So there are 200kb for programm stack. Is it not enogh? However i got TLE. Any suggestions? Re: Whare goes memory? Memory allocation will work very slow of course Try to solve it with simple array without vector Re: Whare goes memory? Posted by Lomir 17 Feb 2007 19:35 UPS... i got not TLE, but MLE.. If I allocate each element, then got TLE... So I desided to use allocate each 12 elemtents, but got MLE... Re: Whare goes memory? Posted by svr 17 Feb 2007 19:58 I think when we use container with each anelement we store pointer and memory size dublicated Re: Whare goes memory? I think that dynamic memory manager can't pack data closely and free space appears Re: Whare goes memory? Posted by Lomir 26 Jun 2007 19:57 Once again! WHY MLE? struct Value { unsigned char value[4]; unsigned char prev[3]; }; Value data[100000]; int top[1001]; int size; int main () { assert(sizeof(Value) == 7); .... It is possible to save only some more (2 or 3) bits. But data alinging will eat them. Also another question: struct stA { int value; unsigned char prev[3]; }; struct stB { int value; int prev : 18; }; struct stC { unsigned char value[4]; unsigned char prev[3]; }; (sizeof(stA) == sizeof(stB) == 8) != (sizeof(stC) == 7) Why? Re: Whare goes memory? MLE Posted by And IV 7 Jul 2007 02:11 //#include<fstream>; #include<iostream>; #include<string> using namespace std; //ofstream cout("out.txt"); //ifstream cin("in.txt"); string ch; struct telem { int val; telem *nx; }; int n,a,b,i; telem *st[1001],*k; int main() { cin>>n; for(i=0;i<n;i++) { cin>>ch;
if (ch=="PUSH") { cin>>b>>a; k=st[b]; st[b]=new telem; st[b]->val=a; st[b]->nx=k; } if (ch=="POP") { cin>>b; cout<<st[b]->val<<endl; k=st[b]->nx; delete(st[b]); st[b]=k; } } return 0 ;} |
|
|