g*******y 发帖数: 1930 | 1 T *pArray = (T*) operator new[](500*sizeof(T));
uninitialized_fill(pArray, pArray+500, int); |
|
o**2 发帖数: 168 | 2 把FMP的版本又优化了一下,很容易就把constructor()和predict()给放到一个active
object里去了,不但constructor()的执行是在worker thread里,而且是on demand的。
在使用原Predictor class的前提下,只增加了PredictorActiveObject和
PredictService这两个classes。
// FMP guarantees every instance a single-threaded env
public class PredictorActiveObject {
private static final AtomicInteger created = new AtomicInteger ();
private Predictor predictor;
// single-threaded
public void init () {
if (predictor == null) {
predictor = new Pre... 阅读全帖 |
|
o**2 发帖数: 168 | 3 如果楼主可以把contructor()里的logic搬到一个init() method里的话,那就没有必要
加新class了,改造原先的Predictor和PredictService就够用的了。
从下面列出原问题的FMP终结版可以看出,FMP和thread,thread pool,
ExecutorService等并发编程技术相比,就象C语言和汇编语言相比,那是全方面的胜出。
public class Predictor {
private boolean inited = false;
// instance-wide single-threaded
public void init () {
if (inited) {
return;
} else {
inited = true;
}
// heavy lifting stuff from original constructor
}
// instance-wide singl... 阅读全帖 |
|
L******e 发帖数: 136 | 4 You need to get IntPtr from that short* right? did you try the code below
the one I quoted, in the same stackoverflow link?
unsafe
{
fixed (int* pArray = array)
{
IntPtr intPtr = new IntPtr((void *) pArray);
}
}
once you get this IntPtr you can do the rest I think.. |
|
s***r 发帖数: 2604 | 5 Yes, I did with following code
Byte[w*h] barray = new byte[w*h]; Mashal.copy((intptr)(img), barray, 0,w*h);
unsafe{fixed(byte* parray=barray)
{InrPtr p= new IntPtr((void* parray));
Bitmap bmp = Bitmap.FromHbitmap(p);}}
same error, on lastline give me "A generic error occured in GDI+"
Is there anything wrong with the code?
do u think the size w,h matters, cz in the run time they are 1066,782 which
is weird to me.
thank u.
在 Leyunque (Le yunque) 的大作中提到: 】 |
|
s****n 发帖数: 700 | 6 【 以下文字转载自 Programming 讨论区 】
发信人: sallen (looking for job), 信区: Programming
标 题: 问个C的typedef问题
发信站: BBS 未名空间站 (Wed Jun 17 22:39:56 2009, 美东)
void *parray[10];
可以写成这样么?
typedef void* eleT;
eleT parray[10]; |
|
s****n 发帖数: 700 | 7 void *parray[10];
可以写成这样么?
typedef void* eleT;
eleT parray[10]; |
|
g****t 发帖数: 39 | 8 Thank you for your reply. For my Linux box, the physical memory is > 600M, the
swap is > 1 G.
I also did a simple test on IBM SP2 node, which has > 60 G memory. However, my
program stops after allocating about 250M memory.
Anything wrong? My program is a super simple one, with "new" in a loop. the
skeleton is as follows:
1. int *pArray[10000];
2. for(i; loop for 10000 or no more memory) pTmp = new int[1mega]; pArray[i] =
pTmp;
My motivation is to find out the upper bound of supportable memory us |
|
M*******8 发帖数: 85 | 9 Is there an error with the sample code shown below? why?
class CLASS
{
public:
CLASS(int x=0);
CLASS(double);
};
int x=10;
CLASS * Parray = new CLASS[x]; |
|