由买买提看人间百态

topics

全部话题 - 话题: pointer
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
b******n
发帖数: 592
1
来自主题: Programming版 - pointer overflow
has anyone experienced pointer overflow in C++. I have a
void * ptr
what I am doing in C++ is :
ptr = reinterpret_cast(ptr)[size]
ugly, but I don't know how to do it prettier.
and the ptr overflowed.
0x7f7ea69f443d is base address
477856 is size
the result is:
0xa69f4440
I found it is very diffult to use raw pointer in C++. For example, if I want
to align the address, I can't do ptr &= ~0xff, something like this.
any suggestion?
b******n
发帖数: 592
2
来自主题: Programming版 - pointer overflow
Sorry, I mis-read traces from my program.
My question is: how to do bit operation on pointers in C++?
I am just trying to adjust pointers by:
ptr &= ~0xf; /* C */
can't seem to do it in C++
b***y
发帖数: 2799
3
来自主题: Programming版 - deque的pointer和reference是怎么回事?
Interestingly, deque's iterators may be invalidated when insertions are made
only at the ends of the container, deque is the only standard STL container
whose iterators may be invalidated without also invalidating its pointers a
nd references.)
deque里不是直接用iterator吗?这pointer和reference是咋个概念?
t****t
发帖数: 6806
4
pointer to function里不准带default parameter [8.3.6]
void g(double (*f)(const double&, const double&));
f的参数个数未知, g当然不能写, 除非你用template
但是即使你用了template, 拿到了(未知参数个数/类型)的function pointer f, 你打
算怎么调用它呢?
d*******n
发帖数: 369
5
来自主题: Programming版 - 关于shared pointer的问题
shared pointer 有个reference count to keep record of how many pointers to an
object. 但是有个地方不明白。比如
std::tr1:shared_ptr int_array(new int);
std::tr1:shared_ptr sec_int_array = int_array;
我看了一下shared_ptr的实现,对于上面的第二句,sec_int_array的reference count
是变成2了,但是好像int_array没变。 对于int_array他仍然认为只有他自己指向这
个int array. 这种inconsistancy 不对吧? 当ini_array变成0是,他会delete the
array too early, right? 因为还有sec_int_array指向它。
谁给解释解释
d*******n
发帖数: 369
6
来自主题: Programming版 - 关于shared pointer的问题
en.是我看错了。shared_ptr composes a pointer to a 'smart' like pointer
X****r
发帖数: 3557
7
来自主题: Programming版 - c++ interview: iterator 和 pointer区别?
That is not the right answer.
In C++, Iterator is a concept. A concept is a set of requirement for
a type. For example, a random access iterator must allow operators
++, +, +=, --, -, -=, [], etc. with the right semantics, while a
forward iterator only needs to have ++. Naked pointers can be
iterators, because they already have these operators built-in.
User-defined types can also be iterators, as long as they overload
required operators correctly.
So the difference between iterator and pointer
t****t
发帖数: 6806
8
来自主题: Programming版 - c++ interview: iterator 和 pointer区别?
等等,你这答案根本不对。iterator is not smart pointer. at all.
which iterator is smart pointer (that can manage resource) in STL? none.
and design pattern is not "想让它作甚,就作甚". in addition, the design patt
ern iterator is not what asked here.
recommended book: effective STL...

现在还有标准的争论么? 我这里大致的用一下,就原则性错误了?
z****e
发帖数: 2024
9
来自主题: Programming版 - c++ interview: iterator 和 pointer区别?
我说过了,iterator 是 smart pointer 这个不是我先发明的,是书上说的,好几本都
出现过这种说法。
这是一个说法,至于什么才是 “smart pointer ”,就是文字游戏和标注之争了。
我完全同意iterator在STL里边不能resource management.但是不带表不能设计一种具有此工能iterator啊。
我思过去了,不敢和二位恩师争。
我错了!

patt
h****b
发帖数: 157
10
来自主题: Programming版 - c++ interview: iterator 和 pointer区别?
想不到大家这么踊跃热情 : )
如果问问什么stl不用pointer (我被问到),可不可以回答 iterator的operator被重载
过,比
pointer更容易使用,比如list的iterator++,直接指向下一个link list element。
另外,请问一下:vector是怎么实现的?我知道是dynamic array, continuous memory
,不
过如果需要resize (e.g. increase size), 怎么能保证还是continuous memory?
谢了
o*******0
发帖数: 699
11
来自主题: Programming版 - smart pointer 一问
smart pointer 实践是不是真的很有用呢?
比方说 auto_ptr, 你要把它定义在stack上,这样它才会自动消除。
可是知道把object定义在stack上,可能就不要auto_ptr了。
又比如说smart pointer with ref count. 要thread safe, 算错了还会死人。(那是
真查不出来的bug)
f******e
发帖数: 582
12
来自主题: Programming版 - Help on pointer analysis for C programs
Hi,
I have a C program my.c and I would like to apply some basic ideas from the
following paper to analyze the pointers used in my.c.
My question is: is there a free open source tool available for me to start
with? the tool mentioned in the following paper seems obsolete..
Thanks a lot.
http://portal.acm.org/citation.cfm?id=1062455.1062520
Title: Improving software security with a C pointer analysis
Full Text: Pdf
Authors: Dzintars Avots
Stanford University, Stanford, CA
Michael Dal... 阅读全帖
E******T
发帖数: 59
13
来自主题: Programming版 - A tough pointer concept

type.
((double (*)[NCA])a)
you are right and a is a pointer, such as definition: double *a;
the confusing part is how we define the array with NCA elements which a
pointer points to.
is this right like ([NCA])a
Thanks
P********e
发帖数: 2610
14
来自主题: Programming版 - A tough pointer concept
that is wrong.
a is a two dimentional array pointer, point to NCA elements of pointer to
double type.
double* a[NCA];
t****t
发帖数: 6806
15
来自主题: Programming版 - c++ pointer conversion question
my point is to show what is improper code: you are not to alias and access
an object with imcompatible type through pointer conversion. for int and
float, maybe it is obvious that you shouldn't do it. but for some other
types, it may not be that obvious: for example, you can't change a void*
through pointer/reference to void**, even if you do casting (e.g. when
x is void*, you can't do (*(void***)(&x)) = ...., even with casting). i
personally fell through that trap several years ago, when i buil... 阅读全帖
a****l
发帖数: 8211
16
来自主题: Programming版 - c++ pointer conversion question
I don't know why it is so complicated. A pointer is a pointer, as long as
you know where it points to, you can cast it to anything you want. The code
is simply pointing to the binary of a float and try to interpret it as
integer, which surprises me that sometimes it actually would work.
v******l
发帖数: 512
17
来自主题: Programming版 - c++ pointer conversion question
I don't quite get what you mean by "can not alias it". Your sample code is a
typical aliasing and as long as there is no memory issue (overflow or
something) there is nothing wrong with it.
Look at it this way: You need a buffer by using malloc you get a big chunk
of memory pointed by void *p0. There is nothing wrong you first cast it to
int* and fill it with a bunch of integers, then cast to float* and reads
them out as floats. It is merely a re-interpretation of data and it behaves
just like a... 阅读全帖
r****t
发帖数: 10904
18
以前一直不自觉的用,如果所有 unqualified-id 都默认是通过 this pointer, 是不
是 this pointer 是完全不必要的?
w***g
发帖数: 5958
19
来自主题: Programming版 - stl的interator是一种smart pointer吗
不是。iterator是pointer的推广,并不一定需要用pointer来实现。
g***l
发帖数: 2753
20
来自主题: Programming版 - 请教一个C++中function pointer的问题。
一个模块,原先是在C中写的,现在要用C++重新写,因为要添加新的功能。
情况是如下:
程序运行中,能够拿到一段数据,存在连续的memory中,uint8_t *data={30,23,.....
...},data[1]用来当tag_id用,不同tag_id要调用不同对象的处理函数,data[2]是表
示数据的长度。
在原来的C中,我是建立了一个 function pointer look up table,用data[1]来搜索,
返回相应的function pointer : void(*pfunc)(uint8_t* in_data_p,uint8_t * out_
result_p).
在C++中,现在每个对象都是一个单独的class,从base class继承来的。
class base_class
{
public:
uint8_t tag_id;
std::vector result;
public:
virtual ProcessData(uint8_t * in_data_p);
};
然后每个对象的class定义如下:
clas... 阅读全帖
t****t
发帖数: 6806
21
1st one is returning pointer/reference to local, which is wrong
2nd one is returning value of local, which is correct.
BTW you don't say "return local", you say "return pointer/reference/address
of local"
t****t
发帖数: 6806
22
第二个是pointer to string literal, pointer类型怎么转换都是string literal.
r*******n
发帖数: 3020
23
seriously?
C++里不能避免用pointer吧
g****u
发帖数: 252
24
最好不用pointer.
b*******s
发帖数: 5216
25
try boost's smart pointers
N******K
发帖数: 10202
26
来自主题: Programming版 - 关于不同类型的smart pointer
比较古老的的一些程序 用的是 Intrusive smart pointer 就是 那个 reference
counter 保存在object里面
std里面的改为单独存一个 reference counter,然后每个smart pointer都要指向这个
reference counter和object
各位都用的是哪一种?
哪种好?
r*********r
发帖数: 3195
27
returning a pointer that points to local objects?
that's called a dangling pointer.
j******t
发帖数: 788
28
来自主题: Programming版 - C++的smart pointer注定是个二流的东西
This is exactly smart pointer is doing. Call destructor while leaving the
scope, and delete the raw pointer. Am I right?
"所有的资源都在同一对花括号内获取和释放,指针根本不会用
错"
E*******1
发帖数: 3464
29
来自主题: Programming版 - C++的smart pointer注定是个二流的东西
你smart pointer可能没用好吧,怎么说smart pointer是个二流的东西。这玩意主要是
针对执行出错,throw了,结果跳过后面的delete内存释放步骤造成leak的解决方案
k**********g
发帖数: 989
30
来自主题: Programming版 - 关于多个smart pointer系统并存的问题

The minimum requirement is that at least one of the smart pointer
implementation needs to support a user-provided deleter function (instead of
using the default delete operator of that type).
If this is only satisfied by one side, a one-way wrapping is possible.
Ideally, two-way wrapping is more desirable.
I have implemented a similar interoperable wrapper between OpenCV Mat class
and COM smart pointer. I do not have the source code right now, but it
basically uses the deleter function.
Since I... 阅读全帖
N******K
发帖数: 10202
31
另外 std::shared_ptr等比 intrusive smart pointer好 因为对每一个object 有一个
manager object 然后所有指针都指向 manager object
如果 object被干掉了 可以从manager object判断出来
如果多个raw指针指向一个object。 当这个object被干掉 这些 raw指针都指向垃圾
如果多个shared_ptr/weak_ptr指针通过manager object指向一个object, 当object被
干掉 这些 weak_ptr通过manager object指向Null pointer
如果每一个object都有一个指向自己的weak_ptr为成员变量 那就跟好了
t*****n
发帖数: 4908
32
你到底学啥的?说过多少遍了,smart pointer不是让程序员偷懒,而是让程序更健壮
。比起不负责随便分配内存的某语言来说,smart pointer是相当靠谱。
weak_ptr你再读读boost的网页吧。解释的很清楚。
l***l
发帖数: 41
33
来自主题: Programming版 - 什么时候使用c++ smart pointer?
比如写一个链表,是不是使用smart pointer更好一点?是不是只要需要用new和delete
的地方都应该用smart pointer?
n****1
发帖数: 1136
34
来自主题: Programming版 - 什么时候使用c++ smart pointer?
smart pointer缺点:
1. 多线程下非常麻烦, 因为一般的智能指针都不是线程安全的.
2. 给人错误的安全感,让人放松对内存泄漏的警惕性. 如果程序员一不小心忽略了某个
pointer cycle的话, 内存就漏大发了.
r*g
发帖数: 3159
35
来自主题: Programming版 - 什么时候使用c++ smart pointer?
应该问,什么时候stack变量加stl容器还不够用,需要用 pointer,然后再问什么时候
用smart pointer。
w*******y
发帖数: 60932
36
Meritline
Compact 3 in 1 White and Blue LED Flashlight with Laser Pointer:
http://www.meritline.com/3-in-1-led-flashlight-laser-pointer-403---p-34998.aspx?source=nl100830&hq_e=el&hq_m=2034655&hq_l=104&hq_v=f2d37cccb6
$0.99 with code MLCK600403083051NL1
free shipping
w*******y
发帖数: 60932
37
Meritline
Hand Squeeze Flashlight w/ Double LED and Lanyard:
http://www.meritline.com/mini-squeeze-light-w-double-led---p-25404.aspx
$0.99 w/ code MLCK248005111180AL1
3 in 1 Red Laser Pointer, Flashlight and Banknote Checking:
http://www.meritline.com/laser-pointer-flashlight-banknote-checking---p-37421.aspx
$0.79 w/ code MLCK400438111168AL1
Mini Wireless Bluetooth USB 2.0 Adapter:
http://www.meritline.com/mini-wireless-bluetooth-usb-20-adapter---p-27752.aspx?
$0.99 w/ code MLCK192102111171AL1
N... 阅读全帖
w*******y
发帖数: 60932
38
1 Pack2-LED with Laser Pointer Key Chain Black Torch Flashlight, Random
Color (More Details)
Coupon Code :MLCK188974120271AL1 limit 800 uses
Link:
http://www.meritline.com/led-laser-pointer-key-chain-torch-974---p-35285.aspx
w*******y
发帖数: 60932
39
1 Pack3 in 1 Red Laser Pointer, Flashlight and Banknote Checking (More
Details)
Coupon Code :MLCK400438121668AL1 limit 800 uses
Link:
http://www.meritline.com/laser-pointer-flashlight-banknote-checking---p-37421.aspx
w*******y
发帖数: 60932
40
1 Pack2-LED with Laser Pointer Key Chain Black Torch Flashlight, Random
Color (More Details)
Coupon Code :MLCK188974122780NL1 limit 1000 uses
Link:
http://www.meritline.com/led-laser-pointer-key-chain-torch-974---p-35285.aspx
w*******y
发帖数: 60932
41
1 PackCompact 3 in 1 White and Blue LED Flashlight with Laser Pointer,
Random Color (More Details)
Coupon Code :MLCK600403122869AL1 limit 500 uses
Link:
http://www.meritline.com/3-in-1-led-flashlight-laser-pointer-403---p-34998.aspx
w*******y
发帖数: 60932
42
Logitech Professional Presenter R800 with Green Laser Pointer:
http://www.amazon.com/Logitech-Professional-Presenter-Green-Poi
rebate form:
http://g-ecx.images-amazon.com/images/G/01/00/00/13/76/31/71/13
Technical Details
* Brilliant green laser pointer is easy to see on any presentation
screen--even in a brightly lit room
* LCD display with timer and silent vibrating alerts help you manage
time without watching the clock
* Up to 100-foot wireless range for freedom to move and mingle... 阅读全帖
w*******y
发帖数: 60932
43
*Starts at 8:00 am Pacficic*
Meritline
2-LED with Laser Pointer Key Chain Black Torch Flashlight:
http://www.meritline.com/led-laser-pointer-key-chain-torch-974-
$0.99 w/ code MLCK5Z20PETNL1
Free shipping
w*******y
发帖数: 60932
44
Survival Tool:
http://www.meritline.com/stainless-steel-survival-tool---p-2726
$0.99fs
Coupon Code: MLCK10A3NL1
Laser Pointer:
http://www.meritline.com/3-in-1-red-laser-pointer-ball-point-pe
$0.89fs
Coupon Code: MLCK10A3NL1
Bluetooth Adapter:
http://www.meritline.com/mini-wireless-bluetooth-v2-0-usb-2-0-a
$0.99fs
Coupon Code: MLCK10A3NL1
3 Pcs SATA Cables:
http://www.meritline.com/straight-to-right-serial-ata-sata-data
$0.99fs
Coupon Code: MLCK10A3NL1
w*******y
发帖数: 60932
45
150mw 532nm Open-back Green Laser Pointer with Keychain(Ligniting matches)
Link:
http://www.dailyshop.com/green-laser-pointer-keychain-150mw.htm
v***t
发帖数: 27100
46
红色激光笔,锁男做演讲必备,放家里当枪用。
巴马儿子晚上来了的话,用laser pointer一照,人家以为你上了AK47呢
w******o
发帖数: 3259
m****u
发帖数: 43
48
来自主题: Faculty版 - 请大家推荐个laser pointer
我用kensington的,觉得不错哦。
Kensington Si600 Wireless Presenter with Laser Pointer - Presentation remote
control - radio
g*******y
发帖数: 1930
49
change function pointer to a functor should be ok
template class CMP{
public:
operator()(const T &t1, const T &t2){ return t1 };
template class Heap{
public:
Heap(const vector &data, CMP cmp);
};

I
o**********t
发帖数: 406
50
you cannot allocate a new block of RAM in sub function if you pass pointer.
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)