endl or “\n” ?

Posted on Updated on


well this is for c++ programmers.

std::endl and “\n” has just one difference

std::endl calls flush stream but “\n” does not.

Why should i prefer “\n” over endl?

Specially in Loops using “\n” improves performance significantly.

When should i go for std::endl over “\n” ?

#include <iostream>
int main(){
unsigned int i=3;
std::cout<<i<<std::endl;
while(i-=2);
std::cout<<“out Of Loop”;
return 0;
}

This program prints i because endl will flush stream

 

#include <iostream>

int main(){
unsigned int i=3;
std::cout<<i;
while(i-=2);
std::cout<<“out Of Loop”;
return 0;
}

This program does not prints i because no one flushes stream.

It is programmer’s choice whether to use std::endl or “\n” and also depends on program requirement

I would suggest not to use std::endl inside loops, but

if your program contains loops which can lead to infinite loop, then use std::flush before entering loop.

You can use

std::cout<<std::flush;

before entering doubtful loops

 

 

 

Microsoft changed completely in just 3 months

Posted on


Microsoft as an enterprise company:

Microsoft has been recently seen to be changing a lot of its tactics. The company which is seen as an epitome of enterprise software is slowly molding itself into cloud based services. At last, Microsoft has realized that now they are the underdogs of consumer market and hence needs to step up to keep pace with Google.

Microsoft gets most of its revenue from enterprise software. Company’s consumer products like Windows phone, Xbox, Bing and other services doesn’t serve that much to its overall revenue. While the stock investors does see those products as liability, Steve Ballmer (former CEO) has sought to keep the products in the market.

The changes:

Nadela is cloud services veteran, he knows that the future is running Microsoft’s software on every device using cloud. Well that every device includes Android and iOS. The early tactics suggested to keep Microsoft’s unique products like Office to Windows but now they have been considering other options.

Microsoft Office – Recently, Office was released on iOS. The touch based Office experience is what everyone was waiting for. And this touch based Office is not even released on Microsoft’s own Windows 8. It suggests that the company has changed its view and has started considering to release its software on rival platforms. This marks an important milestone to the company, not only they have ended the Apple war but now they see a rival device like any other device.

Metro UI – This tile based look was made to separate the power users (who use the real desktop) and the casual users (grandma and grandpa). The casual users do not need to go to desktop, now that they can access much of the needed stuff in the Metro UI. Well,  this was the vision behind the tiles but recently the company has updated the OS to bring back the start menu and to boot directly to desktop.

Xbox Live gold subscription – Just a few days ago, the company has made some of the paid entertainment services free.

Windows – Windows is now free for all devices with 9 inch or smaller screens, a major business model change.

Development tools – Company has convinced developers to write more apps on windows platform now that the app once written can work on windows 8, windows phone and xbox.

The vision:

Given all the above changes, Microsoft is ‘not just kidding’, its really serious. Heck! even Nadela fired the top 2 managers for not completely ‘in’ for the changes. In coming years, the company sees to expand its services and make software accessible to all using cloud.

Windwos 8.1 Skype Sending file failed and takes drive space

Posted on Updated on


On windows 8.1,

Skype app file transfer is done by temporary copying those file in appdata of current user

suppose,  user name is bhushan  so this is path to my data on local machine

C:\Users\Bhushan\AppData\Local\Packages\Microsoft.SkypeApp_kzf8qxf38zg5c\LocalState\bhushan

Then SendingStorage is for files you are sending and ReceiveStorage are file receiving

completely received files are stored in Current user\Downloads by default

If you encounter disk full because of large file sending failed,

Option 1: You can just delete those files from SendinfStorage folder.

Option 2: Move your appdata location to other drive having large disk space

you can relocate appdata by mklink command, but this command is to be executed while you are not running windows,

Run windows using bootable DVD or going into repar menu and command prompt.

 

Microsoft offer $100 for XP

Posted on Updated on


After April 8, 2014, support and security updates for XP will no longer be available.

Microsoft trying to motivate customers around globe to upgrade PC’s to windows 8.1.

So here is the offer from microsoft

read microsoft support is ending

Microsoft Store to use offer

Don’t have windows Xp and want offer ?

Read the rest of this entry »

Some Interesting Pointer Tricks

Posted on Updated on


I was browsing on Quora when I stumbled across some interesting answers on pointers. They were worth sharing, so here they are with the sources mentioned at the bottom.

 

Encoding information in the low-order bits of pointers.

The setup: The memory addresses of objects are aligned to specific boundaries—generally what we call natural alignment, which means objects are aligned to a memory address that is a multiple of their size. So a 64-bit integer is aligned to an eight-byte boundary;

0x7fff315470d8

is a proper

long

pointer on x86-64 but

0x7fff315470d9

is not. If a pointer is always aligned to an eight-byte boundary, then the low-order three bits are always zero.

The trick: You can stick whatever you want in those low-order bits, so long as you take them out before dereferencing the pointer. If your bottom three bits have to be zero, then you get three bits of “free” storage. To make this easy, you define a couple macros. One macro (called

POINTER()

in my example) masks out the low-order bits and returns a proper pointer. Another macro (

DATA()

in my example) masks out the high-order bits and returns the encoded data. To prevent the accidental dereferencing of the pointer before masking out the encoded data—which, aside from the pointer not pointing directly at your data, might be an alignment violation—the usual pattern is to store your pointers in

unsigned long

types, although a

uintptr_t

is a more portable alternative.

Example: Here’s an example, which defines three flags that you may OR into the pointer. Note this particular example requires a platform where pointers and longs are both 64-bits, but you could easily modify it for a 32-bit system.

 

</pre>
#include <stdio.h>

#define POINTER(p) (unsigned long*)(p & 0xffffffffffffff8UL)
#define DATA(p) (p & 7)

#define FLAG1 1
#define FLAG2 2
#define FLAG3 4

int main() {
unsigned long v = 0;
unsigned long p = (unsigned long) &v;

printf("p=%lu\n", p);
printf("POINTER(p)=%p\n", POINTER(p));
printf("DATA(p)=%lu\n", DATA(p));

p |= FLAG2;

printf("p=%lu\n", p);
printf("POINTER(p)=%p\n", POINTER(p));
printf("DATA(p)=%lu\n", DATA(p));

return 0;
}

Cool, but this seems like more work than it is worth? Often true! This sort of trick is useful when you have many, many pointers. For example, this is a common technique when implementing memory management systems where you might have a pointer to every active page in the system. Three bits with which to set read & write access flags are all you need.

Source: http://www.quora.com/C-programming-language/In-C-or-C++-what-are-your-favorite-pointer-tricks/answer/Robert-Love-1

 

 

Creating a doubly linked list with a single pointer

You can make a doubly linked list with a single pointer, which actually stores the XOR of its previous and next nodes’ addresses. For the head, this will just be the next element’s address.

Now, when traversing the list in the forward direction, instead of doing

n = n->next

, you do

n = n->next ^ prev

For the reverse direction, note that the tail’s next pointer will actually contain its previous node. So to traverse backwards, you just start with

n = tail
1
2
3
4
5
6
node *n = (forward ? head : tail), *prev = 0, *t;
while(/* some condition */) {
    t = n;
    n = n->next ^ prev;
    prev = t;
}

.

Insertion and deletion are similarly modified.

All of this is just a cute trick though- you should probably not use it unless writing code for some heavily memory constrained embedded system.

Source: http://www.quora.com/C-programming-language/In-C-or-C++-what-are-your-favorite-pointer-tricks/answer/Shrey-Banga

 

String Copy

while(*t++ = *s++) ;