looking for C++ users to make a C++ discussion group

坦白的说我对C++的前途比较悲观,C++不会消亡,但是会在其他语言的挤压之下应用面会越来越小。现在的软件越来越复杂,开发效率和可维护性已经超过了运行效率,但是C++语言本身的特性注定了培养一个合格的C++程序员的难度。C++的标准化远远落后于其他语言,迄今没有一个统一的跨平台的类库。唉!
 
最初由 dpff 发布
坦白的说我对C++的前途比较悲观,C++不会消亡,但是会在其他语言的挤压之下应用面会越来越小。现在的软件越来越复杂,开发效率和可维护性已经超过了运行效率,但是C++语言本身的特性注定了培养一个合格的C++程序员的难度。C++的标准化远远落后于其他语言,迄今没有一个统一的跨平台的类库。唉!


I agree with you!
So it is suitable for some softwares that need efficency and more development efficency,
assembly < C < C++ < ...
 
come on! we just want to learn and gain some experence. If you are willing to help us see this or understand what you said by ourself instead of just hearing from you, i belive you could make a big jump on your knowledge too!


QUOTE]最初由 dpff 发布
坦白的说我对C++的前途比较悲观,C++不会消亡,但是会在其他语言的挤压之下应用面会越来越小。现在的软件越来越复杂,开发效率和可维护性已经超过了运行效率,但是C++语言本身的特性注定了培养一个合格的C++程序员的难度。C++的标准化远远落后于其他语言,迄今没有一个统一的跨平台的类库。唉! [/QUOTE]
 
比较理解和支持 Fisher 的初衷.

找一个PROJECT做是个好办法,因为C++应用太杂,很难使讨论凭空产生凝聚力和持续性.

最好的办法是做一个可能赢利的项目,一举两得.
 
It would be great if we can make a project which is profitable. My initial idea is that we can exchange some coding experiences among us and improve our coding skills. In this way, we can improve ourselves and become more productive. Then, it is easier for us to keep our jobs or find new jobs. Examples for exchange: 1. always set pointer to be NULL after a pointer is deleted. If this pointer is accidently deleted again, nothing will happen. Otherwise, it will cause crashes. 2. use non-recursive quick-sort to sort an array. On Windows, recursive quick-sort can cause stack-overflow (crash) when an array is too big. Such kind of problems can be easily solved. However, if you know them earlier, you can avoid coding them in your work.
 
How about we start with coding the problem 2: non-recursive quick sort and then we could exchange the code or ideas? Do you mind to give us some detail on this problem, so we could have the same starting point?

for me, I don;t do c++ daily, and I need time to get it done.

最初由 Fisher 发布
It would be great if we can make a project which is profitable. My initial idea is that we can exchange some coding experiences among us and improve our coding skills. In this way, we can improve ourselves and become more productive. Then, it is easier for us to keep our jobs or find new jobs. Examples for exchange: 1. always set pointer to be NULL after a pointer is deleted. If this pointer is accidently deleted again, nothing will happen. Otherwise, it will cause crashes. 2. use non-recursive quick-sort to sort an array. On Windows, recursive quick-sort can cause stack-overflow (crash) when an array is too big. Such kind of problems can be easily solved. However, if you know them earlier, you can avoid coding them in your work.
 
Actually, you can easily find some source codes on the web. The problem (stack-overflow) appears on Windows (no problem on other platforms) when two vectors (size around 25000) are sorted after a GUI application is launched. My version of quick-sorting two vectors in increasing order of the first vector:

#include <iostream>
#include <stack>
#include <vector>
#include <stdlib.h>
using namespace std;

template< class T1, class T2 >
inline void swap( vector< T1 > & vec1, vector< T2 > & vec2, int a, int b )
{
T1 tmp1 = vec1[ a ];
T2 tmp2 = vec2[ a ];

vec1[ a ] = vec1[ b ]; vec2[ a ] = vec2[ b ];
vec1[ b ] = tmp1; vec2[ b ] = tmp2;
}

template< class T1, class T2 >
void quicksort( vector< T1 > & vec1, vector< T2 > & vec2 )
{
stack< int > help_stack;

help_stack.push( 0 );
help_stack.push( vec1.size() - 1 );

while( !help_stack.empty() )
{
int right = help_stack.top(); help_stack.pop();
int left = help_stack.top(); help_stack.pop();

if ( left >= right )
{
continue;
}

int next_index = left + ( int ) ( ( right - left + 1 ) * ( ( double ) rand() / ( double ) RAND_MAX ) );
swap( vec1, vec2, next_index, right );

T1 p = vec1[ right ];

int a = left;
int b = right - 1;

while( a <= b )
{
while (a <= b && vec1[a ] <= p )
{
a++;
}

while (a <= b && vec1 >= p )
{
b--;
}

if ( a < b )
{
swap( vec1, vec2, a, b );
}
}

swap( vec1, vec2, a, right );
help_stack.push( a + 1 );
help_stack.push( right );
help_stack.push( left );
help_stack.push( a - 1 );
}
}

int main()
{
unsigned i, size = 50;
double value1, value2;
vector< double > vec1;
vector< double > vec2;

for ( i = 0; i < size; ++i )
{
value1 = size * ( ( double ) rand() / ( double ) RAND_MAX );
vec1.push_back( value1 );

value2 = size * ( ( double ) rand() / ( double ) RAND_MAX );
vec2.push_back( value2 );
}

cout << "\n arrays before sorting \n" << endl;

for ( i = 0; i < size; ++i )
{
cout << " i = " << i << " " << vec1[ i ] << " " << vec2[ i ] << endl;
}

quicksort( vec1, vec2 );

cout << "\n arrays after sorting \n" << endl;

for ( i = 0; i < size; ++i )
{
cout << " i = " << i << " " << vec1[ i ] << " " << vec2[ i ] << endl;
}

return 0;
}
 
通常来说,现在支持VM的操作系统,在32bits的CPU下每个进程都有4GB地址空间,windows好象是内核一G,共享一G,进程地址空间2G,然后排除代码空间,你的vec25000=25K,大小25K*8=200K也并不大,这是数据,quicksort我也没看到迭代调用啊?另外就是多少线程在运行,我觉得可以调试一下,看一下是不是由于迭代引起的,我现在真有些看不懂C++了,还是C简单。另外在vxworks下,线程栈空间是可以调整的,默认可能小些,这要根据自己而定。
不过,也很高兴和你们讨论,可能说错了,请指教。
 
使用第归的算法是有栈溢出的危险。VC中默认的栈和堆大小都是1M,可以通过链接开关修改,但是治标不治本。最安全的做法是将第归改为循环。上面的代码没有细看,应该是去掉了第归。另外VC自带的CRT也实现了快速排序(qsort),好像也没有使用第归,可以参考qsort.c。
 
I think you are right. Normally you can call sort() in <algorithm> to sort one vector. However, without local copies of two or more vectors (inefficient), you can not use sort() to sort more than two vectors. The code I posted is a non-recursive version. The recursive version caused stack-overflow.
 
These are only small examples. If many of us can share only a little bit, we all will get much better.
It is better for us to meet each other regularly. This kind of meeting requires devotion. However, we will profit from each other dearly.
 
非常希望大家聚聚。
至于 VC的栈的限制,我倒觉得无所谓,我不太记得windows下的进程结构,不过都应该是栈和堆向一个方向走,而且windows也不会分只有一M吧!我现在没有vc,我会用gcc试一下,看一下地址。现在基本都是保护模式了,应该不象以前64K限制了。
 
去掉递归是对的,最起码效率不够,虽然编码简单。
 
#include <stdio.h>
#include <stdarg.h>

int main(void)
{

int a, b;
char * addr1, *addr2;

addr2 = (char*)malloc(1024*1024*256);
addr1 = (char*)malloc(1024);
if (addr2) free(addr2);
if (addr1) free(addr1);

a =1, b=2;

test_stdcall(a,b);
test_fastcall(a,b);
test_cdecall(a,b);


test_stdcall_var("%d %d\n",a,b);
test_fastcall_var("%d %d\n",a,b);
test_cdecall_var("%d %d\n",a, b);

return 0;
}

用这个小程序测了一下,用gcc编译的,可以看出代码段在中间,栈在最下面,堆在上面,并且似乎从0xa000000开始,并且向上分配,栈是向下分配的,基本从0x22ef00左右开始,我只是看了main里面的局部变量,和堆地址。
大概栈2M多些,堆应该说从0xa000,000开始以上,一直到windows的共享空间和内核空间0x80000000,应该说地址空间是足够了对一般程序,大概接近2G。 我并没有找资料,可能有错误,也只是个大概数字。
和linux的应用程序地址空间分配差别较大。
如果要把动态分配的内存再大些,windows提示虚拟内存不够,这也和linux不一样。看来大家的虚拟内存管理也不一样。
 
再加个栈分配:
int c[1024*256];
int d[1024*256];
如果是一个c,OK程序没问题,已经是1M字节了,如果再分1M,程序栈溢出,忘了一些固定的地址映射,把d大小改为128*1024没问题,看来栈应该大于1M小于2M了,默认情况下。
linux下栈和堆都是在代码段的上面,从高到低和从低到高,所以栈的空间非常大。同时 X86的用户空间可以达到3G,好象是,可能和其它CPU混了。
 
后退
顶部